在内存中的BITMAPINFO上写文本

时间:2018-08-07 11:03:02

标签: c++ image bmp

我从.avi视频中以BITMAPINFO的形式检索一帧,我想在其上写一个字符串,我不想使用OpenCV。我可以编写一个库来手动更改图像中像素的颜色以形成字母,但这会花费很多时间。图像是32位RGBA

/// For each rectangle in the vector it test if it intersects with another and return the set of united rectangles. 
/// \param v A set of rectangles
/// \return A united set of rectangles.
std::vector<rectangle> test_intersect_and_unite(const std::vector<rectangle> &v)
{
    std::vector<rectangle> united;

    // ...

    return united;
}

1 个答案:

答案 0 :(得分:0)

使用GDI功能或Gdiplus用DrawTextTextOut绘制文本。位图可能颠倒了,可能必须翻转。检查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);