1

I have a WICBitmap that contains an image in my MFC program. Is there any way to draw this bitmap onto a device context?

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

}
Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
xcdemon05
  • 1,372
  • 5
  • 25
  • 49

2 Answers2

2

There are a number of samples on MSDN that show how to display a WIC bitmap using, for example, GDI, GDI+, Direct2D etc.


Microsoft provides a WIC Image Viewer Using GDI Sample (GitHub mirror)

The basic idea is:

Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
Roger Rowland
  • 25,885
  • 11
  • 72
  • 113
  • Can you link to any samples on MSDN that show to display a WIC bitmap using GDI or GDI+? Or, better yet, post the code? (the link you gave seems stale - has no code) – Ian Boyd Apr 05 '17 at 03:31
  • @IanBoyd Yes, sorry, although that link works ok, MSDN has removed those examples! There are others available though- a quick Google [found this blog](http://www.nuonsoft.com/blog/2011/10/17/introduction-to-wic-how-to-use-wic-to-load-an-image-and-draw-it-with-gdi/comment-page-1/), which shows how to render a WIC bitmap using GDI. Although I *could* copy/paste the author's code in my answer, I'm not sure that would be entirely ethical, even with suitable attribution. Maybe that link helps? – Roger Rowland Apr 05 '17 at 05:32
-1

The file can be edited separately as bmp file, and after you can load WIC object as you can see in How to Load a Bitmap from a File.

Mihai8
  • 3,113
  • 1
  • 21
  • 31