| image - handle of the image to measure |
|
Returns the width of an image in pixels. Pair it with ImageHeight and you can lay a screen out from the artwork rather than from magic numbers: centre a logo with (GraphicsWidth()-ImageWidth(logo))/2, wrap a sprite around the edge of the play field, or size a tile grid from the tile itself. For an animated image this is the width of one frame - the cell width you gave LoadAnimImage - not the width of the source sheet. It always reports the image's current size, so it updates after ScaleImage, ResizeImage or RotateImage. See also: ImageHeight, ImageXHandle, ImageYHandle, LoadImage, GraphicsWidth. |
; ImageWidth Example
; ------------------
Graphics 640,480,0,2
SetBuffer BackBuffer()
logo=LoadImage("media/b3dlogo.jpg")
; Read the image's size in pixels
w=ImageWidth(logo)
h=ImageHeight(logo)
While Not KeyDown(1)
Cls
DrawImage logo,120,140
; Measurement guides drawn from the returned values
Color 255,255,0
Line 120,130,120+w,130 ; width guide along the top
Line 120,130-4,120,130+4
Line 120+w,130-4,120+w,130+4
Text 120+w/2,110,"ImageWidth = "+w,True
Color 128,128,128
Line 110,140,110,140+h ; height guide down the side
Text 0,0,"Esc: exit"
Text 0,20,"ImageWidth(logo)="+w+" ImageHeight(logo)="+h
Flip
Wend
End