0

I'm struggling with FreeImage and the documentation is not helping me a lot!

I need to display a tif, an exr or an HDR image in a picturebox with C# and I'm not succeeding and I wonder how can I do it... I'm getting the error: Only bitmaps with type of FIT_BITMAP can be converted. ...

Can anyone help me with it ? I suppose I have to convert the tiff to a bitmap but I've tried but I don't know how I should do it yet ... Here is my code:

    FIBITMAP imageToDisplay = new FIBITMAP();
    imageToDisplay = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_TIFF, i, FREE_IMAGE_LOAD_FLAGS.TIFF_CMYK);
    Bitmap bitmap = FreeImage.GetBitmap(imageToDisplay);
    pictureBox.Image = (Image)new Bitmap(bitmap);            
user1782638
  • 130
  • 1
  • 13
  • I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders Feb 11 '13 at 16:27
  • Thanks! I forgot to check the title after assigning the tags! :) – user1782638 Feb 11 '13 at 16:31

1 Answers1

0

For displaying TIFFs, PictureBox.Image takes a System.Drawing.Image object - and System.Drawing.Image.FromFile() supports TIFF images.

I can't see any need to involve any third party dependencies here. It's all built in to the framework.

pictureBox.Image = Image.FromFile(someImage);

If your TIFF isn't a file (e.g. if it's just a byte array or a MemoryStream) - that's okay too - use Image.FromStream().

For unsupported file formats, your job is to convert them into a format supported by System.Drawing.Image. If this is not possible, you might not be able to use the PictureBox control for this job.

Perhaps the title of your question should be "Constructing Image objects from EXR files" or maybe "Displaying EXR files in Windows Forms" or similar.

tomfanning
  • 9,552
  • 4
  • 50
  • 78
  • Thank your for your help. Unfortunately the FromFile() gives me out of memory and the file is about 6mb .. the FromStream() gives me invalid parameter :( That is why I tried to go with FreeImage but I get Only bitmaps with type of FIT_BITMAP can be converted. :( – user1782638 Feb 11 '13 at 16:54
  • From the documentation for `Image.FromFile()`: "If the file does not have a valid image format or if GDI+ does not support the pixel format of the file, this method throws an OutOfMemoryException exception." – tomfanning Feb 11 '13 at 17:00
  • So it seems that my tiff is not supported .. Do you know how can I process it in order to be processed? Because it is a valid TIF file... Or else I have to convert it to bitmap with freeimage... – user1782638 Feb 11 '13 at 17:07
  • No. What drew you to FreeImage? Are you sure it can do what you are asking? – tomfanning Feb 11 '13 at 17:11
  • I've saw that is compatible with HDR, EXR and TIFF .. I can load the images but I'm not able to process them to show in the PictureBox :( – user1782638 Feb 11 '13 at 17:12