ImageConvertRow
 
将一行图像数据转换为另一种颜色深度

语法

Declare Sub ImageConvertRow ( ByVal src As Any Ptr, ByVal src_bpp As Integer, ByVal dst As Any Ptr, ByVal dst_bpp As Integer, ByVal width As Integer, ByVal isrgb As Integer = 1 )

用法

ImageConvertRow( src , src_bpp , dst , dst_bpp , width [, isrgb ] )

参数

src
源行的起始地址。源可以是像素深度为每像素24位或32位的全色图像,或者每像素位深为1-8位的调色图像。如果您进行转换时,如果您处于使用正确的图像调色板的屏幕模式,则转换调色图像将只能正常工作。
src_bpp
源行中每像素的位数。1-8,24和32。
dst
目的地行的起始地址。图像可以是每像素16或32位的全色图像。如果源是调色图像,则目的地也可以是每像素1到8位的调色图像。
dst_bpp
目标行中每像素的位数。有效值为1-8,16和32。
width
行的长度(以像素为单位)
isrgb
值为零表示红色和蓝色通道在源图像中相反。如果要在转换中交换红色和蓝色通道,请使用此开关。

说明

将图像的一行从一个存储器位置复制到另一个存储器位置,将每个像素中的颜色信息转换为与目标图像相匹配。

例子

#include "fbgfx.bi"
#if __FB_LANG__ = "fb"
Using FB
#endif

Const As Integer w = 64, h = 64
Dim As IMAGE Ptr img8, img32
Dim As Integer x, y


''创建一个32位图像,大小w * h:
ScreenRes 1, 1, 32, , GFX_NULL
img32 = ImageCreate(w, h)

If img32 = 0 Then Print "ImageImreate在img32上??失败!": Sleep: End


''创建一个8位图像,大小w * h:
ScreenRes 1, 1, 8, , GFX_NULL
img8 = ImageCreate(w, h)

If img8 = 0 Then Print "ImageGreate在img8上失败!": Sleep: End


''用图案填充8位图像
For y = 0 To h - 1
    For x = 0 To w - 1
        PSet img8, (x, y), 56 + (x + y) Mod 24
    Next x
Next y


''在8位模式下打开图形窗口,并将图像输入:
ScreenRes 320, 200, 8
WindowTitle "8位彩色模式"
Put (10, 10), img8

Sleep


''将图像数据复制到32位图像中
Dim As Byte Ptr p8, p32
Dim As Integer pitch8, pitch32

#ifndef ImageInfo '' older versions of FB don't have the ImageInfo feature
#define GETPITCH(img_) IIf(img_->Type=PUT_HEADER_NEW,img_->pitch,img_->old.width*img_->old.bpp)
#define GETP(img_) CPtr(Byte Ptr,img_)+IIf(img_->Type=PUT_HEADER_NEW,SizeOf(PUT_HEADER),SizeOf(_OLD_HEADER))
pitch8 = GETPITCH(img8): p8 = GETP(img8)
pitch32 = GETPITCH(img32): p32 = GETP(img32)
#else
ImageInfo( img8,  , , , pitch8,  p8  )
ImageInfo( img32, , , , pitch32, p32 )
#endif

For y = 0 To h - 1
    ImageConvertRow(@p8 [ y * pitch8 ],  8, _
                    @p32[ y * pitch32], 32, _
                    w)
Next y


''在32位模式下打开图形窗口并将图像输入:
ScreenRes 320, 200, 32
WindowTitle "32位彩色模式"
Put (10, 10), img32

Sleep


''从内存中释放图像:
ImageDestroy img8
ImageDestroy img32


方言差异

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

与QB差别

  • 新的FreeBASIC

参考