绘制WICBitmap到窗口

Draw WICBitmap to window?

本文关键字:窗口 WICBitmap 绘制      更新时间:2023-10-16

我有一个WICBitmap,在我的MFC程序中包含一个图像。有没有办法把这个位图画到设备上下文上?

void DrawBitmap(IWICBitmapSource source, HDC targetDC, int X, int Y, int cx, int cy)
{
   //source: The Bitmap to draw
   //TargetDC: The HDC to draw onto (e.g. a printer or screen DC)
   //X,Y: The location on the DC to draw the bitmap
}

MSDN上有许多示例,展示了如何使用GDI, GDI+, Direct2D等显示WIC位图。

  • MSDN:图像解码样本(存档)
  • WIC简介:如何使用WIC加载图像,并使用GDI绘制图像?(归档)

Microsoft提供了一个使用GDI示例的WIC图像查看器(GitHub镜像)

基本思想是:

  • IWicBitmapSource转换为标准的Windows BITMAP(CreateDibSectionFromBitmapSource)
  • 使用位图绘制使用您的标准工具

该文件可以单独编辑为bmp文件,加载WIC对象后,您可以看到如何从文件加载位图