BitBlt and StretchBlt are the CDC class bitmap manipulation functions for the DDB bitmap operation.
BOOL BitBlt (HDC hdcdest,int nxdest,int nydest,int nwidth,int nheight,hdc hdcsrc,int nxsrc,int nysrc,dword dwRop)
BOOL StretchBlt (hdc hdcdest, int nxorigindest, int nyorigindest, int nwidthdest, int nheighdest, hdc hdcsrc, int nxorigins RC, int nyoriginsrc, int nwidthsrc, int nheightsrc, DWORD dwrop)
Hdcdest: A handle to the target device environment.
Nxdest: Specifies the x-axis logical coordinates of the upper-left corner of the target rectangle area.
Nydest: Specifies the y-axis logical coordinates of the upper-left corner of the target rectangle area.
Nwidth: Specifies the logical width of the source and destination rectangular regions.
Nheight: Specifies the logical height of the source and destination rectangular regions.
HDCSRC: A handle to the source device environment.
NXSRC: Specifies the x-axis logical coordinates of the upper-left corner of the source rectangular area.
NYSRC: Specifies the y-axis logical coordinates of the upper-left corner of the source rectangular area.
NWIDTHSRC: Specifies the width of the source rectangle, in logical units.
NHEIGHTSRC: Specifies the height of the source rectangle, expressed in logical units.
The
nxdest nydest nxsrc NYSRC is specified as the starting point under the logical coordinate system. In DC and memory DC, the DC and memory DC logical coordinate system can be different, that is, SetWindowExt and setwindoworg parameters can not be the same, if the exact same can be used BitBlt, if not the same, it is best to set the direction of the Axis consistent, Can be used StretchBlt, if the direction is inconsistent, the image may be up or down or left and right upside down.
Dwrop: Specifies the raster operation code. The code defines the color data for the source rectangle area, and how to combine the color data from the destination rectangle area to finish the final color.
Some common raster operation codes are listed below:
Blackness: Indicates that the target rectangle area is populated with the color associated with index 0 of the physical palette (which is black for the default physical palette).
Dstinvert: Indicates that the target rectangle area color is reversed.
Mergecopy: Indicates that the color of the source rectangle area is combined with a specific pattern using the and (and) operator of the Boolean type.
Mergepaint: Merges the color of the inverse source rectangle area with the color of the destination rectangle area by using the or (or) operator of the Boolean type.
Notsrccopy: The color of the source rectangle is reversed and copied to the target rectangle area.
Notsrcerase: Combines the color values of the source and destination rectangular regions using the or (or) operator of the Boolean type, and then deserializes the color of the composition.
Patcopy: Copies a specific pattern to the target bitmap.
Patpaint: Merges the color values of the source rectangle region with the color of a particular pattern by using the Boolean or (or) operator. The or (or) operator is then used to merge the result of the operation with the color within the target rectangle area.
Patinvert: Merges the colors within the source and destination rectangular regions by using the XOR operator.
Srcand: Merges the colors in the source and destination rectangular areas by using the and (with) operator.
Srccopy: Copies the source rectangle area directly to the destination rectangle area.
Srcerase: Merges the color values of the region of the source rectangle by using the and (and) operator to reverse the color of the target rectangle area.
Srcinvert: Merges the colors of the source and destination rectangle regions by using the XOR operator of the Boolean type.
Srcpaint: Merges the colors of the source and destination rectangle regions by using the or (or) operator of the Boolean type.
Whiteness: Fills the target rectangle area with the color associated with index 1 in the physical palette. (This color is white for the default physical palette).
SetDIBitsToDevice and StretchDIBits are Windows supported DIB Access functions (APIs)
int SetDIBitsToDevice (HDC hdc, int xdest, int ydest, DWORD dwwidth, DWORD dwheight, INTXSRC, int ysrc, UINT ustartscan, UI NT cscanlines, const VOID *lpvbits, const bitmapinfo *LPBMI, UINT fucoloruse)
HDC: Device environment handle.
Xdest: Specifies the x-coordinate of the upper-left corner of the destination rectangle, which represents the coordinates in logical units.
Ydest: Refers to the y-coordinate of the upper-left corner of the target rectangle, which is represented by logical units.
Dwwidth: Specifies the width of the DIB, expressed in logical units.
Dwheight: Specifies the height of the DIB, expressed in logical units.
XSRC: Specifies the x-coordinate of the lower-left corner of the DIB bitmap (regardless of whether biheight is positive or negative), which is represented by logical units.
YSRC: Specifies the y-coordinate of the lower-left corner of the DIB bitmap (regardless of whether biheight is positive or negative), which is represented by logical units.
Uscanlines: Specifies the starting scan line in the DIB.
Cscanlines: Specifies the number of Dib scan lines contained in the array that the parameter lpvbits points to.
Lpvbits: A pointer to an array of byte types that store the DIB color data. To reduce the amount of memory required to set the bits of a large DIB bitmap, the application can call Setdibitstobevice repeatedly. Each time a different part of the bitmap is put into the lpvbits array to bundle the output together. The values of the parameters Ustartscan and cscanlines indicate the portion of the bitmap contained in the lpvbits array.
LPBMI: A pointer to the BITMAPINFO structure that contains information about the DIB.
Fucoloruse: A value that points to the member bmicolors in the BITMAPINFO structure whether it contains an explicit RGB value or an index to the palette.
The parameter fucoloruse must be one of the following values, which have the following meanings:
Dib_pal_colors: Indicates that the color table consists of 16-bit indexed array of values that can be used to index the currently selected logical palette.
Dib_rgb_colors: Indicates that the color table contains the literal RGB values.
Return value: If the function executes successfully, the return value is the number of scan lines set, and if the function fails, the return value is 0.
int StretchDIBits (HDC hdc, int xdest, int ydest, int ndestwidth, int ndestheight, int xsrc, int ysrc, int nsrcwidth, int Nsrcheight, const VOID *lpbits, const bitmapinfo * lpbitsinfo, UINT iusage, DWORD dwrop)
HDC: A handle to the target device environment.
Xdest: Specifies the x-coordinate of the position of the upper-left corner of the destination rectangle, which is represented by logical units.
Ydest: Specifies the y-coordinate of the upper-left corner of the destination rectangle, which represents the coordinates in logical units.
Ndestwidth: Specifies the width of the target rectangle. Draws the area to the right of the xdest, drawing the direction from left to right, the drawing area to the left of the xdest, and the drawing direction from right to left.
Ndestheight: Specifies the height of the target rectangle. Draws an area below the ydest, but draws the direction from bottom to top, and a negative drawing area above the ydest, but draws the direction from top to bottom.
XSRC: Specifies the x-coordinate of the source rectangle (lower-left corner) of the DIB, regardless of whether biheight is positive or negative, and coordinates are expressed in pixels.
YSRC: Specifies the y-coordinate of the source rectangle (lower-left corner) of the DIB, regardless of whether biheight is positive or negative, and coordinates are expressed in pixels.
Nsrcwidth: Specifies the width of the source rectangle in the Dib, in pixels, the right side of the XSRC, the scan direction from left to right, and the left side of the XSRC, and the scan direction from right to left.
Nsrcheight: Specifies the height of the source rectangle in the Dib in pixels, the positive-time selection at the top of the YSRC, the scan direction from bottom to top, and the negative selection area below YSRC, and the scan direction from top to bottom.
Scan rows First, and then scan columns.
Lpbits: A pointer to the DIB bit whose values are stored as an array of byte types.
Lpbitsinfo: A pointer to the BITMAPINFO structure that contains information about the DIB.
Iusage: Indicates whether the member bmicolors in the BITMAPINFO structure is provided, and if so, whether the bmicolors contains an explicit RGB value or index. The parameter iusage must take the following values, meaning the following:
Dib_pal_color: Indicates that the array contains 16-bit index values that are indexed to the logical palette of the source device environment.
Dib_rgb_colors: Indicates that the color table contains the original KGB values, please refer to the Remarks section below for more information.
Dwrop: Specifies how the source pixel points, the current brush of the target device environment, and the target pixel points are combined to form a new image.
Return value: If the function executes successfully, then the return value is the number of scanned lines copied, and if the function fails, the return value is Gdi_error.