Search code examples
asp.net-mvcbitmaptiffsystem.drawing

Creating a bitmap object from tiff image


I have a page with a gallery where users upload images. I noticed that there is one particular user who uploaded 3 tiff images and that they cannot be accessed.

Exception type: System.ArgumentException
Exception message: Parameter is not valid.

It happens here:

using (Image photo = new Bitmap(new MemoryStream(photoData)))

Files seems to be ok, sice File.ReadAllBytes() works, I can download them using other method (the one not working is used for returning a resized image only), test locally and the exception is not thrown. Any ideas what could be the case? Unfortunatelly I dont know yet if this occurs for all tiff images uploaded by other users too.


Solution

  • Support for TIFF flavors (and there are many of them) depends on the version of Windows on your server. More precisely, it depends on GDI+ library's version.

    Without seeing the TIFFs there is nothing more I can tell. But I can recommend you to try some 3rd party libraries just for TIFF files. There is de-facto standard libtiff library and I have ported it to C# some time ago. You might try the port.

    There are some samples you might be interested in. I think Convert color TIFF to a 32-bit System.Drawing.Bitmap might be most eligible for your task.