IMAGECONVERTROW
- 来源: https://www.freebasic.net/wiki/wikka.php?wakka=KeyPgImageConvertRow
- 最后更新: 2022-03-25
将一行图像数据转换为另一种颜色深度
语法
declare sub ImageConvertRow ( byval src as any ptr, byval src_bpp as long, byval dst as any ptr, byval dst_bpp as long, byval width as long, byval isrgb as long = 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
值为零表示源图像中的红色和蓝色通道顺序相反。如果希望在转换中交换红色和蓝色通道,请使用此开关。
说明
将图像的一行从一个内存位置复制到另一个内存位置,并将每个像素中的颜色信息转换以匹配目标图像。
示例
start GeSHi
vb
#include "fbgfx.bi"
#if __FB_LANG__ = "fb"
Using FB
#endif
Const As Long w = 64, h = 64
Dim As IMAGE Ptr img8, img32
Dim As Integer x, y
'' create a 32-bit image, size w*h:
ScreenRes 1, 1, 32, , GFX_NULL
img32 = ImageCreate(w, h)
If img32 = 0 Then Print "Imagecreate failed on img32!": Sleep: End
'' create an 8-bit image, size w*h:
ScreenRes 1, 1, 8, , GFX_NULL
img8 = ImageCreate(w, h)
If img8 = 0 Then Print "Imagecreate failed on img8!": Sleep: End
'' fill 8-bit image with a pattern
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
'' open a graphics window in 8-bit mode, and PUT the image into it:
ScreenRes 320, 200, 8
WindowTitle "8-bit color mode"
Put (10, 10), img8
Sleep
'' copy the image data into a 32-bit image
Dim As Byte Ptr p8, p32
Dim As Long 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
'' open a graphics window in 32-bit mode and PUT the image into it:
ScreenRes 320, 200, 32
WindowTitle "32-bit color mode"
Put (10, 10), img32
Sleep
'' free the images from memory:
ImageDestroy img8
ImageDestroy img32end GeSHi
方言差异
- 在 -lang qb 方言中不可用,除非使用别名
__ImageConvertRow引用。
与 QB 的区别
- FreeBASIC 新增
另请参阅
ScreenResGet (Graphics)Put (Graphics)ImageCreateImageDestroyImageInfo
返回 目录