win32 SetDIBits

SetDIBits

The SetDIBits function sets the pixels in a compatible bitmap (DDB) using the color data found in the specified DIB.

int SetDIBits(
  __in  HDC hdc,
  __in  HBITMAP hbmp,
  __in  UINT uStartScan,
  __in  UINT cScanLines,
  __in  const VOID *lpvBits,
  __in  const BITMAPINFO *lpbmi,
  __in  UINT fuColorUse
);

Parameters

hdc [in]
A handle to a device context.

hbmp [in]
A handle to the compatible bitmap (DDB) that is to be altered using the color data from the specified DIB.

uStartScan [in]
The starting scan line for the device-independent color data in the array pointed to by the lpvBits parameter.

cScanLines [in]
The number of scan lines found in the array containing device-independent color data.

lpvBits [in]
A pointer to the DIB color data, stored as an array of bytes. The format of the bitmap values depends on the biBitCount member of the BITMAPINFO structure pointed to by the lpbmi parameter.

lpbmi [in]
A pointer to a BITMAPINFO structure that contains information about the DIB.

fuColorUse [in]
Indicates whether the bmiColors member of the BITMAPINFO structure was provided and, if so, whether bmiColors contains explicit red, green, blue (RGB) values or palette indexes. The fuColorUse parameter must be one of the following values.

Value Meaning
DIB_PAL_COLORS The color table consists of an array of 16-bit indexes into the logical palette of the device context identified by the hdc parameter.
DIB_RGB_COLORS The color table is provided and contains literal RGB values.

Return Value

If the function succeeds, the return value is the number of scan lines copied.

If the function fails, the return value is zero.

This can be the following value.

Return code Description
ERROR_INVALID_PARAMETER One or more of the input parameters is invalid.

Remarks

Optimal bitmap drawing speed is obtained when the bitmap bits are indexes into the system palette.

Applications can retrieve the system palette colors and indexes by calling the GetSystemPaletteEntries function. After the colors and indexes are retrieved, the application can create the DIB. For more information, see System Palette.

The device context identified by the hdc parameter is used only if the DIB_PAL_COLORS constant is set for the fuColorUse parameter; otherwise it is ignored.

The bitmap identified by the hbmp parameter must not be selected into a device context when the application calls this function.

The scan lines must be aligned on a DWORD except for RLE-compressed bitmaps.

The origin for bottom-up DIBs is the lower-left corner of the bitmap; the origin for top-down DIBs is the upper-left corner of the bitmap.

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.

BITMAPINFO 结构体

The BITMAPINFO structure defines the dimensions and color information for a DIB.

typedef struct tagBITMAPINFO {
  BITMAPINFOHEADER bmiHeader;
  RGBQUAD          bmiColors[1];
} BITMAPINFO, *PBITMAPINFO;

embers

bmiHeader
A BITMAPINFOHEADER structure that contains information about the dimensions of color format.

.

bmiColors
The bmiColors member contains one of the following:

  • An array of RGBQUAD. The elements of the array that make up the color
    table.
  • An array of 16-bit unsigned integers that specifies indexes into the
    currently realized logical palette. This use of bmiColors is allowed
    for functions that use DIBs. When bmiColors elements contain indexes
    to a realized logical palette, they must also call the following
    bitmap functions: CreateDIBitmap

    CreateDIBPatternBrush

    CreateDIBSection

    The iUsage parameter of CreateDIBSection must be set to
    DIB_PAL_COLORS.

The number of entries in the array depends on the values of the biBitCount and biClrUsed members of the BITMAPINFOHEADER structure.

The colors in the bmiColors table appear in order of importance. For more information, see the Remarks section.

Remarks

A DIB consists of two distinct parts: a BITMAPINFO structure describing the dimensions and colors of the bitmap, and an array of bytes defining the pixels of the bitmap. The bits in the array are packed together, but each scan line must be padded with zeroes to end on a LONG data-type boundary. If the height of the bitmap is positive, the bitmap is a bottom-up DIB and its origin is the lower-left corner. If the height is negative, the bitmap is a top-down DIB and its origin is the upper left corner.

A bitmap is packed when the bitmap array immediately follows the BITMAPINFO header. Packed bitmaps are referenced by a single pointer. For packed bitmaps, the biClrUsed member must be set to an even number when using the DIB_PAL_COLORS mode so that the DIB bitmap array starts on a DWORD boundary.

Note

The bmiColors member should not contain palette indexes if the bitmap is to be stored in a file or transferred to another application.

Unless the application has exclusive use and control of the bitmap, the bitmap color table should contain explicit RGB values.

调用SetDIBits修改位图内容 (很好)
https://blog.csdn.net/iamshuke/article/details/5749933

该函数是将DIB中的像素位,改变为DDB中的像素位,是对像素位的改变 调色板 是作为参考的。不会对DIB的调色板进行修改。

猜你喜欢

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