Retrieves information about an image

declare function Imageinfo ( byval image as any ptr, byref width as integer = 0, byref height as integer = 0, byref bypp as integer = 0, byref pitch as integer = 0, byref pixdata as any ptr = 0, byref size as integer = 0 ) as long

result = Imageinfo( image [, [width] [, [height] [, [bypp] [, [pitch] [, [pixdata] [, size]]]]]] )

The address of the image.
Stores the width of the image, in pixels.
Stores the height of the image, in pixels.
Stores the bytes per pixel of the image - i.e. the size of a single pixel, in bytes.
Stores the pitch of the image - i.e. the size of each scanline (row), in bytes. Note that this may be more than just width * bypp, because the scanlines may be padded to allow them to be aligned better in memory.
Stores the address of the start of the first scanline of the image.
Stores the size of the image in memory, in bytes.

Return Value:
If image doesn't point to a valid image, one (1) is returned. Otherwise, width, height, bypp, pitch, pixdata and size are assigned appropriate values, and zero (0) is returned.

ImageInfo provides various information about an image, such as its dimensions and color depth, but also provides you with the information you need to directly access all the pixel data in the pixel buffer.

It can also provide the size of the image in memory, which is useful for allocating memory to copy the existing image, or to write the image to a file.

ImageInfo is an alternative way to access the main characteristics of an image, rather than directly accessing the internal FB.IMAGE structure (defined in through a typed pointer to member data.

The error code returned by ImageInfo can be checked using Err in the next line. The function version of ImageInfo returns directly the error code as a 32 bit Long.

'' pixelptr(): use imageinfo() to find the pointer to a pixel in the image
'' returns null on error or x,y out of bounds
Function pixelptr(ByVal img As Any Ptr, ByVal x As Integer, ByVal y As Integer) As Any Ptr

    Dim As Integer w, h, bypp, pitch
    Dim As Any Ptr pixdata
    Dim As Integer success
    success = (imageinfo(img, w, h, bypp, pitch, pixdata) = 0)
    If success Then
        If x < 0 Or x >= w Then Return 0
        If y < 0 Or y >= h Then Return 0
        Return pixdata + y * pitch + x * bypp
        Return 0
    End If
End Function

'' usage example:

'' 320*200 graphics screen, 8 bits per pixel
ScreenRes 320, 200, 8

Dim As Any Ptr ip '' image pointer

Dim As Byte Ptr pp '' pixel pointer (use byte for 8 bits per pixel)

ip = ImageCreate(32, 32) '' create an image (32*32, 8 bits per pixel)

If ip <> 0 Then

    '' draw a pattern on the image
    For y As Integer = 0 To 31

        For x As Integer = y - 5 To y + 5 Step 5

            '' find the pointer to pixel at x,y position
            '' note: this is inefficient to do for every pixel!
            pp = pixelptr(ip, x, y)

            '' if success, plot a value at the pixel
            If (pp <> 0) Then *pp = 15

        Next x

    Next y

    '' put the image and draw a border around it
    Put (10, 10), ip, PSet
    Line (9, 9)-Step(33, 33), 4, b

    '' destroy the image to reclaim memory
    ImageDestroy ip

    Print "Error creating image!"
End If


Output image for pixelptr() example

'' Create 32-bit graphics screen and image.
ScreenRes 320, 200, 32
Dim image As Any Ptr = ImageCreate( 64, 64 )

Dim pitch As Integer
Dim pixels As Any Ptr

'' Get enough information to iterate through the pixel data.
If 0 <> imageinfo( image, ,,, pitch, pixels ) Then
    Print "unable to retrieve image information."
End If

'' Draw a pattern on the image by directly manipulating pixel memory.
For y As Integer = 0 To 63
    Dim row As ulong Ptr = pixels + y * pitch
    For x As Integer = 0 To 63
        row[x] = RGB(x * 4, y * 4, (x Xor y) * 4)
    Next x
Next y

'' Draw the image onto the screen.
Put (10, 10), image

ImageDestroy( image )


Output image for ImageInfo example

Dialect Differences:
Differences from QB:
See also:
Back to 2D Drawing Functions
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki phatcode