Image and text synthesis

zhaozj2021-02-16  57

Synthesis of image and text: kylin

Download This example is a few days before the project, the text and bitmap images are synthesized and saved as bitmap files. But I have been asked for a long time, no one gives a satisfactory answer, I have to explore in the dark, I have a hard work, realize the image of the image and the text, and can be dragged with the mouse. Now I posted the code, I hope to help the friends you need. First, the key function 1.

INT setDibits (HDC HDC, // Compatible DC handle HBitmap HBMP, // Compatibility bitmap handle uint uStartscan, // Scan the number of startings UINT CSCANLINES, // Scanned Row number const void * lpvbits, // The pointer of the bitmap buffer requires allocated space const bitmapInfo * lpbmi, // bitmap information uint fucoloruse // color format);

This function puts a pixel of a pixel of bitmap data into a partial diagram, and HDC is a compatible DC that selects a compatible bitmap.

2.

INT getDibits (HDC HDC, // Compatible DC handle HBitmap HBMP, // Compatibility bitmap handle uint uStartscan, // Scan the number of startings UINT CSCANLINES, // Scanned Row number LPVOID LPVBITS, // Bitmap The pointer of the buffer requires the space LPbitMapInfo LPBI, // bitmap information uint uusage // color format);

The role of this function is just the opposite of SetDibits, which copies a pixel of a pixel that exists in the compatibility chart to the data buffer (LPVBITS). The implementation of this program is clear, first create a compatible bitmap according to the size of the bitmap, then draw the picture to the compatibility bitmap, then write the text to the compatibility bitmap, then get synthesis from the compatible bitmap The data.

Second, key block

CreateMemObject (CDC * pDC, BITMAPINFO * lpbmi, int * pnLineChar) {if (NULL == m_pMemDC) {m_pMemDC = new CDC (); m_pMemDC-> CreateCompatibleDC (pDC);} if (! M_pMemBmp = NULL) {m_pMemDC-> SelectObject (m_pOldBmp); delete m_pMemBmp; m_pMemBmp = NULL;} m_pMemBmp = new CBitmap (); // Create a compatible bitmap m_pMemBmp-> CreateCompatibleBitmap (pDC, m_lpBMPHdr-> biWidth, m_lpBMPHdr-> biHeight) the size of the image; m_pOldBmp = m_pmemdc-> selectObject (m_pmembmp); m_pmemdc-> FillsolidRect (0, 0, m_lpbmphdr-> biwidth, m_lpbmphdr-> biheight, RGB (255, 255)); // Draw the image of the image to the compatible bitmap SetDIBITS (M_PMEMDC-> getsafehdc (), (hbitmap) m_pmembmp-> m_hobject, 0, m_lpbmphdr-> biheight, (lpvoid) m_lpdibits, (BitmapInfo *) m_lpbmphdr, dib_rgb_colors;

SetBmpText (const CString & strText, BOOL bRepaint) {// this function to add text on the bitmap m_strBmpText = strText; SetDIBits (m_pMemDC-> GetSafeHdc (), (HBITMAP) m_pMemBmp-> m_hObject, 0, m_lpBMPHdr-> biHeight, (LPVOID ) M_LPDIBITS, (BitmapInfo *) m_lpbmphdr, dib_rgb_colors); if (m_strbmptext.getLength ()> 0) {// Manufacture transparent and ghost effect m_pmemdc-> setBkmode (transparent); m_pmemdc-> settextColor (RGB (0, 0, 0)); m_pmemdc-> textout (10, 10, m_strbmptext); m_pmemdc-> setTextColor (RGB (255, 255, 255)); m_pmemdc-> textout (11, 11, m_strbmptext);} if (bowt) {invalidate ();}} SetSaveBmpPath (LPCTSTR pszPath) {// synthesized data extracted from a compatible bitmap BYTE * pTemp = new BYTE [m_dwImageSize]; ZeroMemory (pTemp, m_dwImageSize); int nCount = GetDIBits (m_pMemDC-> GetSafeHdc () , (Hbitmap) m_hobject, 0, m_lpbmphdr-> biheight, (lpvoid) PTEMP, (BitmapInfo *) m_lpbmphdr, dib_rgb_colors);}

Third, legend

Adding a texture

Fourth, conclude

The reading and writing of the bitmap, refer to the VC Knowledge Base Online Magazine No. 21 Hu Zhuo Shi friends

"Bitmap Document Read / Writing Summary"

This program is debugged under Win2000, VC6, 174 * 218 24-bit true color picture.

This program has the following questions:

1. Cannot choose a brush and font in a compatible DC;

2. Take data from the compatible bitmap and is only valid for the true color bitmap.

If you know how to solve the above questions, welcome to enlighten me.

Address: Nanjing Century News Technology Co., Ltd .; MSN: Kylin_wei@hotmail.com

转载请注明原文地址:https://www.9cbs.com/read-19529.html

New Post(0)