How do I use OLE Picture objects with .NET?

Applies to: XpdfViewer, XpdfRasterizer, XpdfImageExtract

Several of the Xpdf components include functions which return OLE Picture objects (the IPicture interface). These can be used in .NET applications, with just a little extra work.

The key is to use .NET's FromHbitmap method to convert the OLE Picture object to a .NET Bitmap object. For example, to use XpdfRasterizer's convertPageToPicture function from VB.net:

Dim pic as stdole.IPicture

...

' convert page 1 to an OLE Picture
pic = rast.convertPageToPicture(1, 125, rast.imageRGB)

' convert the OLE Picture to a .NET Bitmap, and hand it to
' the PictureBox
picBox.Image = Bitmap.FromHbitmap(New IntPtr(pic.Handle))

This applies to the following functions:

  • XpdfViewer.convertPageToPicture
  • XpdfViewer.convertPageToPicture2
  • XpdfViewer.convertRegionToPicture
  • XpdfViewer.convertRegionToPicture2
  • XpdfRasterizer.convertPageToPicture
  • XpdfImageExtract.getPicture