在内存中的BITMAPINFO上写文本 [英] Write text on BITMAPINFO in memory
本文介绍了在内存中的BITMAPINFO上写文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从.avi视频中以BITMAPINFO的形式检索一帧,我想在其上写一个字符串,并且我不想使用OpenCV.我可以编写一个库来手动更改图像中像素的颜色以形成字母,但这会花费很多时间.图像是32位RGBA
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
推荐答案
使用GDI函数(或Gdiplus)以DrawText
或TextOut
绘制文本.位图可能会颠倒,可能必须翻转.检查height
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);
这篇关于在内存中的BITMAPINFO上写文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文