Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bitmap.Save Parameter is not valid

I'm using Bitmap.Save(location,coded,parameters)to save first frame of a tiff image: the encoding scheme used is Tiff format. I then use saveadd() and so on. Works like a charm on win 7 64 bit, but does not work on 32 bit or older windows versions.

After researching I found it might be due to tiff image encoding processed differently with ones before GDI+.

Is there a way to overcome this without any drastic changes?

Sources:

Parameter is not valid calling Bitmap.Save()

http://social.msdn.microsoft.com/Forums/fi-FI/netfxbcl/thread/1585c562-f7a9-4cfd-9674-6855ffaa8653

like image 705
Dexters Avatar asked Mar 01 '13 22:03

Dexters


2 Answers

You must use "long" for the quality parameter

EncoderParameters parametre = new EncoderParameters(1);
parametre.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (quality as long));

or

EncoderParameters parametre = new EncoderParameters(1);
parametre.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 90L);

or

long quality=90; //
EncoderParameters parametre = new EncoderParameters(1);
parametre.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality);
like image 140
mustafa öztürk Avatar answered Oct 23 '22 10:10

mustafa öztürk


Ok, Finally found a resolution. The issue is with the compression format given as one of the input parameters for Save() and how GDI+ works.

Solution 1:

The format for compression needs to be changed to one that is supported in that windows. For e.g) (long)EncoderValue.CompressionLZW compression in .net works in this case instead of (long)EncoderValue.CompressionCCITT4.

But the size of the images will be higher than the one produced from CCITT4. Also CCITT4 is only for bitonal images and LZW fits most images. So just think ahead of these issues ahead, as in most places where tiff image creation are used, not much importance is given to compression used and this issue.

Or an alternative solution can be found below [ I have not tried it though]

Solution 2:

http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/1585c562-f7a9-4cfd-9674-6855ffaa8653/

Additional Reading:

So question on what compression to choose and why may arise for which you can refer to:

https://stackoverflow.com/questions/3478292/whats-the-recommended-tiff-compression-for-color-photos/3480411#3480411

like image 36
Dexters Avatar answered Oct 23 '22 09:10

Dexters