win32 SetDIBitsToDevice

SetDIBitsToDevice

SetDIBitsToDevice function sets the pixels in the specified rectangle on the device that is associated with the destination device context using color data from a DIB, JPEG, or PNG image.
SetDIBitsToDevice 函数 使用 来自 DIB, JPEG 或者PNG图像的颜色数据,设置deivce context 关联的设备上指定的矩形区域的像素。

该设备由目标device context 指定。

int SetDIBitsToDevice(
  __in  HDC hdc,
  __in  int XDest,
  __in  int YDest,
  __in  DWORD dwWidth,
  __in  DWORD dwHeight,
  __in  int XSrc,
  __in  int YSrc,
  __in  UINT uStartScan,
  __in  UINT cScanLines,
  __in  const VOID *lpvBits,
  __in  const BITMAPINFO *lpbmi,
  __in  UINT fuColorUse
);

参数:

hdc [in]
A handle to the device context.

XDest [in]
目标端 矩形左上角 x轴坐标

YDest [in]
目标端 矩形左上角 y轴坐标

dwWidth [in]
DIB或者 JPEG或者 PNG 图像的 宽度.

dwHeight [in]
DIB或者 JPEG或者 PNG 图像的 高度.

XSrc [in]
源端 矩形左上角 x轴坐标

YSrc [in]
源端 矩形左上角 y轴坐标

uStartScan [in]
DIB或者 JPEG或者 PNG 图像的 起始扫描行

扫描二维码关注公众号,回复: 1802113 查看本文章

cScanLines [in]
lpvBits 参数对应的数组中包含的DIB的 扫描行的行数。

lpvBits [in]
字节数组,指向 DIB或者 JPEG或者 PNG 图像的颜色数据

lpbmi [in]
指向BITMAPINFO 结构,该结构包含 DIB 信息。

fuColorUse [in]
指示BITMAPINFO 结构中的bmiColors 成员是包含真实的red,green,blue(RGB)值,还是到调色板的
Indicates whether the bmiColors member of the BITMAPINFO structure contains explicit red, green, blue (RGB) values or indexes into a palette. For more information, see the following Remarks section.

fuColorUse 参数 必须是下列值中的一个.

Value Meaning
DIB_PAL_COLORS The color table consists of an array of 16-bit indexes into the currently selected logical palette.
DIB_RGB_COLORS The color table contains literal RGB values.

返回值

如果函数成功,返回扫描行的行数
如果设置扫描行为0或者函数失败,函数返回0

如果驱动不支持传送SetDIBitsToDevice的JPEG 或者PNG 文件图像,函数将会失败,返回GDI_ERROR 。
如果确实失败了,应用必须将 JPEG 或者PNG支持来解压缩图像为bitmap,然后再将bitmap放入SetDIBitsToDevice。

备注

Optimal bitmap drawing speed is obtained when the bitmap bits are indexes into the system palette.
最快的bitmap绘制速度,需要bitmap 的位 使用系统调色板的索引。

应用可以通过调用GetSystemPaletteEntries函数,获得系统调色板的颜色和索引。
获得颜色和索引之后,应用工可以创建DIB。
如果想要进一步的关于系统调色板的信息,请看Colors

扫描行必须按照DWORD 对齐,除非 是RLE-compressed bitmaps 。

从下到上扫描的DIB的原点是 bitmap的坐下角
从上到下扫描的DIB的原点是bitmap的左上角

设置一个大的DIB的位的时候,需要很大的内存,为了减少这个内存,应用程序,可以多次调用SetDIBitsToDevice函数。
每次取bitmap的一部分进入lpvBits数组。
uStartScan 和 cScanLines的值 确定bitmap的
To reduce the amount of memory required to set bits from a large DIB on a device surface, an application can band the output by repeatedly calling SetDIBitsToDevice, placing a different portion of the bitmap into the lpvBits array each time. The values of the uStartScan and cScanLines parameters identify the portion of the bitmap contained in the lpvBits array.

The SetDIBitsToDevice function returns an error if it is called by a process that is running in the background while a full-screen MS-DOS session runs in the foreground.

If the biCompression member of BITMAPINFOHEADER is BI_JPEG or BI_PNG, lpvBits points to a buffer containing a JPEG or PNG image. The biSizeImage member of specifies the size of the buffer. The fuColorUse parameter must be set to DIB_RGB_COLORS.
To ensure proper metafile spooling while printing, applications must call the CHECKJPEGFORMAT or CHECKPNGFORMAT escape to verify that the printer recognizes the JPEG or PNG image, respectively, before calling SetDIBitsToDevice.
ICM: Color management is performed if color management has been enabled with a call to SetICMMode with the iEnableICM parameter set to ICM_ON. If the bitmap specified by lpbmi has a BITMAPV4HEADER that specifies the gamma and endpoints members, or a BITMAPV5HEADER that specifies either the gamma and endpoints members or the profileData and profileSize members, then the call treats the bitmap’s pixels as being expressed in the color space described by those members, rather than in the device context’s source color space.

例子

For an example, see Testing a Printer for JPEG or PNG Support.

SetDIBitsToDevice(pDC->m_hDC,0,0,bi.biWidth,bi.biHeight,0,0,0,bi.biHeight,lpBuf,pbi,DIB_RGB_COLORS);

具体的 还是参考:
《windows 程序设计(第5版)下册》
第15章

猜你喜欢

转载自blog.csdn.net/wowocpp/article/details/80845530