use*_*749 5 c++ gdi+ image bitmap
我正在用 c++、gdi+ 编写代码。
我使用 Image 的 GetThumbnail() 方法来获取缩略图。但是,我需要将其转换为 HBITMAP。我知道以下代码可以获得 GetHBITMAP:
Bitmap* img;
HBITMAP temp;
Color color;
img->GetHBITMAP(color, &temp); // if img is Bitmap* this works well?
Run Code Online (Sandbox Code Playgroud)
但是如何快速将 Image* 转换为 Bitmap*?非常感谢!
实际上,现在我必须使用以下方法:
int width = sourceImg->GetWidth(); // sourceImg is Image*
int height = sourceImg->GetHeight();
Bitmap* Result;
result = new Bitmap(width, height,PixelFormat32bppRGB);
Graphics gr(result);
//gr.SetInterpolationMode(InterpolationModeHighQuality);
gr.DrawImage(&sourceImg,0,0,width,height);
Run Code Online (Sandbox Code Playgroud)
我真的不知道他们为什么不提供 Image* -> Bitmap* 方法。但是让 GetThumbnail() API 返回一个 Image 对象....
Image* img = ???;
Bitmap* bitmap = new Bitmap(img);
Run Code Online (Sandbox Code Playgroud)
编辑:我正在查看 GDI+ 的 .NET 参考,但以下是 .NET 实现该构造函数的方式。
using (Graphics graphics = null)
{
graphics = Graphics.FromImage(bitmap);
graphics.Clear(Color.Transparent);
graphics.DrawImage(img, 0, 0, width, height);
}
Run Code Online (Sandbox Code Playgroud)
所有这些功能都可以在 GDI+ 的 C++ 版本中使用