Blitz3D+ Command Reference

ImageHeight ( image )

Parameters

image - handle of the image to measure

Description

Returns the height of an image in pixels.

Use it with ImageWidth whenever you need to know how big a sprite is without hard-coding numbers that will break the moment the artist changes the file: centring a title graphic on screen, keeping a sprite inside the play area, working out how many tiles fit down the screen, or setting up a bounding box for your own collision code.

For an animated image this is the height of one frame, not the whole sheet - LoadAnimImage has already cut the strip up, so every frame is the cell height you asked for.

The value reflects the image as it is now, so it changes after ScaleImage, ResizeImage or RotateImage - a rotated image grows to fit its corners.

See also: ImageWidth, ImageXHandle, ImageYHandle, LoadImage, GraphicsHeight.

Example

; ImageHeight 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 110,140,110,140+h            ; height guide down the side
    Line 106,140,114,140
    Line 106,140+h,114,140+h
    Text 10,140+h/2,"ImageHeight = "+h

    Color 128,128,128
    Line 120,130,120+w,130            ; width guide along the top
    Text 0,0,"Esc: exit"
    Text 0,20,"ImageHeight(logo)="+h+"   ImageWidth(logo)="+w

    Flip

Wend

End

Index