如何将类似位图的结构转换为 HDC?
我现在正在用 c++、gdi 编写图像处理程序。
如果我有HDC。我可以通过以下代码在 gdi 中的 HDC 上绘制我喜欢的任何内容。
// HDC is handy.
HDC dc;
dc.DrawXXX // I can draw using gdi method.
Graphics gr(dc); // now I can also draw on the dc using gdi+ method.
我的应用程序基于 FreeImage。我制作了 fipImage。(使用像 Bitmap 这样的数据结构)
但是如果我想在fipWinImage上绘图,现在我必须将fipWinImage复制到Bitmap上,然后在Bitmap上绘图,最后再将位图转换为fipImage,这是耗时耗内存的。
将 fipImage 转换为位图 -> 在位图上绘制 -> 将位图转换为 fipWinImage
fipWinImage imagefip;
Bitmap* tempImg = new Bitmap(imagefip->GetWidth(), imagefip.GetHeigt(), PixelFormat24bppRGB); // memory comsuming is image is large
Graphics *pGr = Graphics::FromImage(tempImg);
HDC dc = pGr->GetHDC();
RECT rec;
rec.left = 0;
rec.top = 0;
rec.right = imagefip.GetWidth();
rec.bottom = imagefip.GetHeight();
fipImage.draw(dc, rec); // using stretchdibits()
pGr->ReleaseHDC(dc);
Graphics gr(tempImg);
HDC dc = gr.GetHDC(); // Get an Hdc, draw using gdi method
gr.ReleaseHDC(tempDC); //
gr.drawXXX // Draw using gdi+ method.
fipWinImage fipImg; // final result fipWinImage.
HBITMAP temp;
Color color;
tempImg->GetHBITMAP(color, &temp);
fipImg->copyFromBitmap(temp);
我想直接从 fipImage 构建一个 HDC。并直接在 fipWinImage 上绘制我该怎么做?