A few days ago to do a program, the text and bitmap image synthesis and save as a bitmap file. But asked for a long time no one to give a satisfactory answer, had to grope in the dark, took some effort to achieve the image and text synthesis, and can drag the mouse text. Now I post the code, hoping to give help to the friend I need.
One, the key function 1.
int SetDIBits(
HDC hdc, // 兼容DC的句柄
HBITMAP hbmp, // 兼容位图的句柄
UINT uStartScan, // 扫描起始行的编号
UINT cScanLines, // 扫描的行的数目
CONST VOID *lpvBits, // 位图缓冲区的指针,要求已经分配空间
CONST BITMAPINFO *lpbmi, // 位图信息
UINT fuColorUse // 颜色格式
);
This function pastes bitmap data one pixel pixel to a compatible bitmap, HDC is a compatible DC with a compatible bitmap selected.
2.
int GetDIBits(
HDC hdc, // 兼容DC的句柄
HBITMAP hbmp, // 兼容位图的句柄
UINT uStartScan, // 扫描起始行的编号
UINT cScanLines, // 扫描的行的数目
LPVOID lpvBits, // 位图缓冲区的指针,要求已经分配空间
LPBITMAPINFO lpbi, // 位图信息
UINT uUsage // 颜色格式
);
This function, in contrast to setdibits, copies the existing data in a compatible bitmap to the data buffer (lpvbits) in pixels of one pixel. So the implementation of the program is more clear, first, according to the size of the bitmap, create a compatible bitmap, and then draw the picture to a compatible bitmap, and then write the text to a compatible bitmap, and then from the compatible bitmap to get the synthesized data.