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); }
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.
System.Drawing.Image img = System.Drawing.Image.FromFile("bitonal.TIF");
img.PixelFormat
Format1bppIndexed
Bitmap bmp = new Bitmap(img);
bmp.PixelFormat
Format32bppArgb
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)