问题
I retrieve a frame from a .avi video as BITMAPINFO and I want to write a string on it, and I dont want to use OpenCV.I could write a library which manually changes the pixel color from the image , to form letters, but it would take a lot of time. The image is 32 bits RGBA
pbmi = (BITMAPINFO*)AVIStreamGetFrame(pgf, i);
BYTE *pPixelSrc = (sizeof(BITMAPINFO) + (BYTE*)pbmi);
long width,height;
width = *((long*)(((BYTE*)pbmi)+4));
height = *((long*)(((BYTE*)pbmi)+8));
//Draw string on data pPixelSrc
回答1:
Use the GDI function, or Gdiplus, to draw text with DrawText
or TextOut
. The bitmap could be upside down, it may have to be flipped. Check the sign for height
int width = pbmi->bmiHeader.biWidth;
int height = pbmi->bmiHeader.biHeight;
auto hdc = GetDC(0);
auto memdc = CreateCompatibleDC(hdc);
auto hbitmap = CreateBitmap(width, height, 1, 32, pPixelSrc);
auto oldbmp = SelectObject(memdc, hbitmap);
TextOut(memdc, 0, 0, "123", 3);
SelectObject(memdc, oldbmp);
GetDIBits(memdc, hbitmap, 0, height, pPixelSrc, pbmi, 0);
DeleteObject(hbitmap);
DeleteDC(memdc);
ReleaseDC(0, hdc);
来源:https://stackoverflow.com/questions/51725207/write-text-on-bitmapinfo-in-memory