Click here to Skip to main content
15,905,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

I got the above exception while saving my image. Please help me out.
My code is below....

Using SaveDialog i pass the inputpath and outputpath parameters to the CONVERT_TIFF() function.

Actually i save an particular image inside my application path as "Bitmap" and Convert it into "TIFF" using compression
SOURCE is here...
http://msdn.microsoft.com/en-us/library/system.drawing.imaging.encoder.compression.aspx[^]

Private void SAVE()
{
bitmap = new Bitmap(PicturePreview.Image);           

            StatusLabel.Text = "Saving Image...";
            string ID = null;
           
            ID = Microsoft.VisualBasic.Interaction.InputBox("Enter Signature Name to Save", "Save As", "", 150, 250);
               if (ID != "")
                {
                    if (!System.IO.Directory.Exists("C:\\Signature"))
                    {
                        System.IO.Directory.CreateDirectory("C:\\Signature");
                        DirectoryInfo oMyDirectoryInfo = new DirectoryInfo("C:\\Signature");
                        //if (!oMyDirectoryInfo.Exists)
                        //{
                        oMyDirectoryInfo.Create();
                        string admin = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();

                        System.Security.AccessControl.DirectorySecurity oDirectorySecurity = oMyDirectoryInfo.GetAccessControl();
                        oDirectorySecurity.AddAccessRule(new FileSystemAccessRule(admin, FileSystemRights.FullControl, InheritanceFlags.ObjectInherit, PropagationFlags.InheritOnly, AccessControlType.Allow));
                        oMyDirectoryInfo.SetAccessControl(oDirectorySecurity);
                        //}
                    }
                    string saveLocation = "C:\\Signature\\" + ID + ".tiff";

                    //Image img = (Image)bitmap.Clone();
                    //img.Save(saveLocation,ImageFormat.Tiff);
                    //img.Dispose();
                   // System.Threading.Thread.Sleep(1000);
                    try
                    {
                        ImageCodecInfo myImageCodecInfo;
                        System.Drawing.Imaging.Encoder myEncoder;
                        EncoderParameter myEncoderParameter;
                        EncoderParameters myEncoderParameters;
                        Bitmap myBitmap = bitmap;

                                               
                        myImageCodecInfo = GetEncoderInfo("image/tiff");
                        myEncoder = System.Drawing.Imaging.Encoder.Compression;

                        myEncoderParameters = new EncoderParameters(1);
                        myEncoderParameter = new EncoderParameter(myEncoder, (long)EncoderValue.CompressionCCITT3);
                        myEncoderParameters.Param[0] = myEncoderParameter;

                        //myBitmap.Save(Application.StartupPath + "\\output.tif", ImageFormat.Tiff);

                        myBitmap.Save(saveLocation, myImageCodecInfo, myEncoderParameters);       
                                         
                    }
                    catch (Exception exp)
                    {
                        
                    }


                     MessageBox.Show("Signature saved Successfully, " + "Check \'" + saveLocation + "\' for Output", "Topaz Sign", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
Posted
Updated 4-Oct-11 23:30pm
v4

1 solution

I found this[^] on CodeGuru:
I had the same problem, until I reduced my image to bitonal. CompressionCCITT4 is valid only for bitonal images.

You may *think* you're working with a bitonal image, but check the PixelFormat in the debugger and you will be surprised. For example, if you load your image thus
C#
System.Drawing.Image img = System.Drawing.Image.FromFile("bitonal.TIF");

then, yes, img.PixelFormat will be Format1bppIndexed, but when you put the image in a bitmap with
C#
Bitmap bmp = new Bitmap(img);

you'll see that bmp.PixelFormat is Format32bppArgb!

See http://www.bobpowell.net/onebit.htm[^] for an excellent discussion of how to make an image bitonal, along with sample code.
 
Share this answer
 
Comments
J.Karthick 5-Oct-11 5:12am    
ya....thanks for your Link Andre Kraak

But it seems Tiff files are not supported for XP i think. Because while i run in WIN7 its works perfect but in XP it just create an INVALID IMAGE.

Do you know more about it?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900