Vector illustration integration into the bitmap programming summary
The vector fusion is actually the program to open a bitmap (called BMP), then draw some graphics or text (called VG), VG is fused to BMP, which is fundamentally changing BMP data. content.
After determining the problem you need, you can do it.
First, this is a simpler problem before doing in-depth consideration, so put it until the last process. Because this feature is generally existed. Open a bitmap - Draw - Save the bitmap, then the information is drawn is saved on the bitmap.
After careful consideration, I feel that I really think about it. When opening a bitmap, the bitmap data is saved to a memory data area. When the program reads this bitmap information into the device context, then display it, and we draw graphics through the CDC device, then reside Save in the memory in memory. Open our saved bitmap found that there is no graphics we draw, the image is still an image. Review the process of the entire modification bitmap found that there is no dry system when drawing the graphics using the CDC. In turn, thinking that since VG and BMP are displayed through the device, then this device must have information on BMP and VG. Expand ideas and reconsider this problem. Since there is something I need on the device, it will be able to take it out. After some considering the formation of from the device context, the method is formed as follows:
Hbitmap CimageStudiodoc :: GetSrcbit (HDC HDC, CRECT)
{
??? HDC HBUFDC;
??? hbitmap hbitmap, hbitTemp;
??? // Create a device context (HDC)
??? HBUFDC = CreateCompaTibleDC (HDC);
??? // Create hbitmap
??? hbitmap = createcompatibleBitmap (HDC, Rect.width (), Rect.Height ());
??? HbitTemp = (hbitmap) SelectObject (HBUFDC, HBitmap);?
??? // Get a bitmap buffer
??? Bitblt (HbufDC, 0, 0, Rect.width (), Rect.height (),
?????? HDC, Rect.Left, Rect.top, / * bitwidth, bitHheight, * / srccopy;
??? // Get the final bitmap information
??? hbitmap = (hbitmap) SelectObject (HBUFDC, HbitTemp);
??? // Release memory
??? deleteObject (hbitTemp);
??? :: deletedc (hbufdc);
??? Return hbitmap;
}
The function returns bitmap information, below with it to refresh bitmap memory data: m_ddb.detach (); // Clear the original data
m_ddb.attach (hbitmap); // Add a new bitmap to the memory data area
The result is amazed, it is a copy screen! ! ! The bitmap returned from the device is all the information on the current screen. The only one can be adjusted to copy one of the zones! There is also an error, that is, the bitmap is not replaced by the bitmap data used to refresh, and the original state is restored when the document data is refreshed! Two questions, one bit is not what I need; two m_ddb.detach (); m_ddb.attach (hbitmap); if the bitmap already exists, the two lines of code have problems, and there is nothing I want to use. The bitmap replaces the original bitmap. This is definitely not the data I want, I want to be data in the bitmap area, whether it is displayed or not displayed, and replacing the original bitmap data. In the trouble, find relevant information online, rarely talk about the drawing text into the bitmap, only a few articles are also rough talks about the problem of drawing text. An article talks about first selection of the device, then draws text on this device, but does not return the bitmap data I want to get. But this article suggests that I first select the bitmap into the device and draw the text. The method of selecting the bitmap will return information on the original device:
CBitMap * PoldbitMap = DcMemory.selectObject (& Bitmap); This function returns Bitmap to Poldbitmap; ! Re-test:
CBITMAP * SRCBMP;
... // Through some methods, get the original bitmap
CBITMAP * PoldbitMap = DCMEMORY.SELECTOBJECT (srcbmp);
GetDocument () -> m_object.draw (& DCMEMORY, this); // Draw vector
SrcBMP = DCMemory.selectObject (PoldbitMap); // By this return bitmap
But the program is wrong, nor does it know where it is wrong. See MSDN ...
After using the use of the device context, it has seen an article that combines bitmap and text and saved as a bitmap. It is found that the data buffer of the last save bitmap is filled with SrcBMP, then srcbmp is not me. What you need! ! ! A surprise, I really looked back. Complete the following code:
Hbitmap hbitmap;
CBitmap Bitmap;
Hbitmap = getDocument () -> m_pimg.getddbitmap ();
Bitmap.attach (hbitmap);?
CDC * PDC = this-> getdc ();
CDC DCMEMORY;?
DcMemory.createCompaTibleDC (PDC);???
CBITMAP * POLDBITMAP = DCMEMORY.SELECTOBJECT (& BITMAP);???
GetDocument () -> M_Object.draw (& DCMEMORY, this); ??????
DCMemory.selectObject (Poldbitmap);
GetDocument () -> m_ddb.detach ();
GetDocument () -> m_ddb.attach (hbitmap) bitmap.getsafehandle ());??
Bitmap.deleteObject ();???
DcMemory.deletedc ();
This-> ReleaseDC (PDC);
GetDocument () -> UpdateAllViews (NULL); program run error! Debug Discovery Bitmap has data, error in getDocument () -> m_ddb.attach ((hbitmap) Bitmap.getsafehandle ()) does not really replace the original bitmap. When Bitmap is empty, it will not report an error. This method is to provide colleagues, so ask him for help, finally solved. The original refresh bitmap area is replaced by the following method: getDocument () -> m_pimg.getdibitmap (hbitmap) Bitmap.getsafehandle ());
Finally, this feature was completed, and it took three days. However, the CDC's drawing mechanism is found.
CBITMAP * POLDBITMAP = DCMEMORY.SELECTOBJECT (& BITMAP);???
GetDocument () -> M_Object.draw (& DCMEMORY, this); ??????
DCMemory.selectObject (Poldbitmap);
BitMap is selected and the device is binded to the device. All the information drawn on the device will be added to Bitmap, so do not need to return when the device is last recovering, directly using Bitmap (different from the option) , Add graphical information).