CDC::BITBLT Introduction
2011-11-04 08:25 19576 People read review (6) Favorite Report
From
http://blog.csdn.net/bberdong/article/details/6934270
There are many ways to draw a device context. For example, by creating a bit drawing brush, you can use it to fill an area to achieve image rendering. In addition, you can use the CDC class's bitmap function to output a bitmap to the device context.
The BitBlt is used to copy bitmaps from the original device to the target device in the following syntax format:
Boolbitblt (int x,int y,int nwidth,int nheight,cdc*psrcdc,int xsrc,int ysrc,dworddwrop);
X: The x-axis coordinate point of the upper-left corner of the target rectangle area.
Y: the y-axis coordinate point of the upper-left corner of the target rectangle area.
Nwidth: Draws the width of the bitmap in the target device.
Nhight: The height of the bitmap is drawn on the target device.
PSRCDC: Pointer to the source device context object.
XSRC: The origin x-axis coordinate of the source device context from which the function copies the bitmap to the target device.
YSRC: The Origin y-coordinate of the source device context from which the function copies the bitmap to the target device.
Dwrop: Raster Operation code
Dwrop has the following options:
Blackness fill the target area with black
Dstinvert target matrix region color inversion
Mergecopy the color of the rectangular area of the original device and the paint brush of the target device using the combined operation
Mergepaint uses or operations to merge the color of the source rectangle area of the inverse and the color of the destination rectangle area
Notsrccopy Copy the reverse color from the source device region to the target device
Notsrcerase uses or operations to combine the color of the source device area with the target device area and then reverse the resulting color
Patcopy Copy the currently selected brush from the source device to the target device
Patinvert the color of the brush and target device area selected by the target device using the XOR operation
Patpaint the color of the currently selected brush and source device area of the target area through or operations
Srcand the color of the source device and target device area using the combined operation
Srccopy Direct replication of the source device area to the target device
Srcerase using the inverse color of the target device area with the operation and the color of the source device area
Srcinvert combination of source device area color and target device area color using XOR operation
Srcpaint use or operation combination source device area color and target device area color
Whiteness fill the target area with white
StretchBlt differs from BitBlt in that the StretchBlt method can extend or shrink a bitmap to fit the size of the target area. The format is as follows:boolstrevhblt (int x,int y,int nwidth,int nheight,cdc* psrcdc,int xsrc,int ysrc,intnsrcwidth,int nSrcHeight, DWORD dwrop);
X: The x-axis coordinate point of the upper-left corner of the target rectangle area.
Y: the y-axis coordinate point of the upper-left corner of the target rectangle area.
Nwidth: Draws the width of the bitmap in the target device.
Nhight: The height of the bitmap is drawn on the target device.
PSRCDC: Pointer to the source device context object.
XSRC: The origin x-axis coordinate of the source device context from which the function copies the bitmap to the target device.
YSRC: The Origin y-coordinate of the source device context from which the function copies the bitmap to the target device.
Nsrcwidth; the width of the bitmap that needs to be copied.
Nsrcheight; the bitmap height to copy.
Dwrop: Raster operation code.
Here are the two methods of comparing the program, the program code is as follows:
void Coutoutbmpview::ondraw (cdc* pDC)
{
coutputbmpdoc* PDoc =getdocument ();//Get Document Object
Assert_valid (PDOC);//Validate Document Object
CDC memdc;//defines a device context
Memdc.createcompatibledc (PDC);//Create a compatible device context
CBitmap bmp;//defining Bitmap objects
Bmp. LoadBitmap (IDB_BKBITMAP);//Load bitmap
Memdc.selectobject (&bmp);//Select Bitmap Object
Pdc->bitblt (30,20,180,180,&memdc,1,1,srccopy);//Draw bitmap
The above is the use of BitBlt to draw bitmaps
CRect RC (30,20,210,200);//define an area
CBrush Brush (RGB (0,0,0));//define a black paint brush
Pdc->framerect (Rc,&brush);//Draw a rectangular border
Just to see the difference between the two, draw a rectangular box
Rc. Offsetrect (220,0);//Mobile Area
Below is a bitmap drawn using StretchBlt.
BITMAP bitinfo;//defining a bitmap structure
Bmp. Getbitmap (&bitinfo);//Get bitmap information
int x = bitinfo.bmwidth;//Gets the bitmap width
int y = bitinfo.bmheight; get bitmap height
Pdc->stretchblt (RC.LEFT,RC.TOP,RC. Width (), RC. Height (), &memdc,0,0,x,y,srccopy);//Draw bitmap
Pdc->framerect (Rc,&brush);//Draw Border
Brush. DeleteObject ();//Release Paint brush
Memdc.deletedc ();//Release device context
Bmp. DeleteObject ();//Release Bitmap object
}
"MFC" Cdc::bitblt Introduction