Write text on BITMAPINFO in memory

蓝咒 提交于 2019-12-11 18:17:59

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!