Skip to content

IMAGEINFO


检索图像信息

语法

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

用法

vb
in the LONG (or INTEGER`<32>`) version of the function:

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

in the LONGINT (or INTEGER`<64>`) version of the function:

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

参数

image

图像的地址。

width

存储图像的宽度(以像素为单位)。

height

存储图像的高度(以像素为单位)。

bypp

存储图像的每像素字节数,即单个像素的大小(以字节为单位)。

pitch

存储图像的行间距,即每条扫描线(行)的大小(以字节为单位)。注意这可能大于 width * bypp,因为扫描线可能会填充以使其在内存中更好地对齐。

pixdata

存储图像第一条扫描线起始位置的地址。

size

存储图像在内存中的大小(以字节为单位)。

返回值

如果 image 没有指向有效图像,则返回一(1)。否则,为 widthheightbypppitchpixdatasize 分配适当的值,并返回零(0)。

说明

ImageInfo 提供有关图像的各种信息,例如其尺寸和颜色深度,还提供直接访问像素缓冲区中所有像素数据所需的信息。

它还可以提供图像在内存中的大小,这对于为复制现有图像分配内存或将图像写入文件非常有用。

ImageInfo 是访问图像主要特性的替代方式,而不是通过类型化指针直接访问内部 FB.IMAGE 结构(在 fbgfx.bi 中定义)的成员数据。

ImageInfo 返回的错误代码可以在下一行使用 Err 检查。ImageInfo 的函数版本直接将错误代码作为 32 位 Long 返回。

示例

start GeSHi

vb
'' 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 Long w, h, bypp, pitch
    Dim As Any Ptr pixdata
    Dim As Long result
   
    result = imageinfo(img, w, h, bypp, pitch, pixdata)
   
    If result = 0 Then '' seems like a valid image
        If x `< 0 Or x >`= w Then Return 0
        If y `< 0 Or y >`= h Then Return 0
        Return pixdata + y * pitch + x * bypp
    Else
        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

Else
    Print "Error creating image!"
End If

Sleep

end GeSHi

start GeSHi

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

Dim pitch As Long
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."
    Sleep
    End
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 )

Sleep

end GeSHi

版本

  • fbc 1.08.0 之前:

方言差异

  • -lang qb 方言中不可用,除非使用别名 __Imageinfo 引用。

与 QB 的区别

  • FreeBASIC 新增

另请参阅

返回 目录

基于 FreeBASIC 官方文档翻译 如有侵权请联系我们删除
FreeBASIC 是开源项目,与微软公司无隶属关系