Introduction to bitblt

Source: Internet
Author: User

There are many ways to draw the device context. For example, you can create a bitmap image brush and use it to fill an area to draw an image. In addition, the bitmap function of the CDC class can be used to output the bitmap to the device context.

Bitblt is used to copy bitmap from the original device to the target device. The syntax format is as follows:

Boolbitblt (int x, int y, int nwidth, int nheight, CDC * psrcdc, int xsrc, int ysrc, dworddwdrop );

X: coordinate point on the X axis in the upper left corner of the target rectangle.

Y: coordinates of the Y axis in the upper left corner of the target rectangle.

Nwidth: the width of the bitmap to be drawn on the target device.

Nhight: draws the height of a bitmap on the target device.

Psrcdc: the context Object Pointer of the source device.

Xsrc: The X-axis coordinate of the start point of the source device context. The function copies the bitmap from this start point to the target device.

Ysrc: the Y axis coordinate of the start point of the source device context. The function copies the bitmap from this start point to the target device.

Dwrop: grating operation code

Dwdrop has the following options:

Blackness uses black to fill the target area

Dstinvert reverse color of the target matrix Area

Mergecopy combines the color of the original device's rectangle area with the image brush of the target device.

Mergepaint combines the color of the Reverse source rectangle area with the color of the target rectangle area using the or operation.

Notsrccopy copies the reverse color of the Source Device area to the target device.

NOTSRCERASE uses or to combine the color of the source and target device areas, and then returns the reversed color.

Copy the selected image from the source device to the target device.

Patinvert combines the paint brush selected by the target device and the color of the target device area using an exclusive or operation.

Patpaint combines the selected paint brush in the target region by or and the reversed color in the source device region.

Srcand uses the color of the Source Device and target device area in combination with the operation

Srccopy directly copies the source device region to the target device.

Srcerase combines the reversed color of the target device region with the color of the Source Device region.

SRCINVERT uses an exclusive or operation to combine the source device region color and the target device region color.

Srcpaint uses or to combine the source device region color and target device region color

Whiteness fills the target area with white

The difference between stretchblt and bitblt is that the stretchblt method can extend or contract the bitmap to adapt to 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, intnscwidth, int nscheight, DWORD dwdrop );

 

X: coordinate point on the X axis in the upper left corner of the target rectangle.

Y: coordinates of the Y axis in the upper left corner of the target rectangle.

Nwidth: the width of the bitmap to be drawn on the target device.

Nhight: draws the height of a bitmap on the target device.

Psrcdc: the context Object Pointer of the source device.

Xsrc: The X-axis coordinate of the start point of the source device context. The function copies the bitmap from this start point to the target device.

Ysrc: the Y axis coordinate of the start point of the source device context. The function copies the bitmap from this start point to the target device.

Nscwidth; specifies the width of the bitmap to be copied.

Nscheight; specifies the height of the bitmap to be copied.

Dwdrop: grating operation code.


The following two Methods Compare the program. The program code is as follows:

Void coutoutbmp view: ondraw (CDC * PDC)

{

Coutputbmp Doc * pdoc = getdocument (); // get the Document Object

Assert_valid (pdoc); // verify the Document Object

CDC memdc; // defines a device context

Memdc. createcompatibledc (PDC); // create a compatible device context

Cbitmap BMP; // defines a bitmap object.

BMP. loadbitmap (idb_bkbitmap); // load the bitmap

Memdc. SelectObject (& BMP); // select a bitmap object

PDC-> bitblt (180,180, & memdc, srccopy); // draw a bitmap

// The above uses bitblt to draw a bitmap.

Crect RC (210,200,); // defines a region

Cbrush brush (RGB (, 0); // defines a black brush

PDC-> framerect (RC, & brush); // draw a rectangular border

// Only used to observe the difference between the two, draw a Rectangular Box

RC. offsetrect (); // move the area

// Below is the bitmap drawn using stretchblt

Bitmap bitinfo; // defines the bitmap structure.

BMP. getbitmap (& bitinfo); // retrieves bitmap Information

Int x = bitinfo. bmwidth; // obtain the bitmap width.

Int y = bitinfo. bmheight; obtain the bitmap height.

PDC-> stretchblt (RC. left, RC. top, RC. width (), RC. height (), & memdc, X, Y, srccopy); // draw a bitmap

PDC-> framerect (RC, & brush); // draw a border

Brush. deleteobject (); // release the paint brush

Memdc. deletedc (); // release the device context

BMP. deleteobject (); // release a bitmap object

}


Introduction to bitblt

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.