473,385 Members | 1,292 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Having a problem with CompressionCCITT3

Adding a second page to the tiff file always fails. Here is the code.
The first time it creates and compresses the image, but when I tries to
"bm.SaveAdd(eps);" it fails. Thanks.

private void CompressTIFF(string outputFile)
{
try
{
Bitmap myImage =
(Bitmap)Image.FromFile(outputFile);
int ix = 0;
Type myType = myImage.GetType();
int iCount =
myImage.GetFrameCount( FrameDimension.Page );
EncoderParameters ep = new
EncoderParameters(3);
System.Drawing.Imaging.Encoder eng =
System.Drawing.Imaging.Encoder.SaveFlag;
System.Drawing.Imaging.Encoder eng1 =
System.Drawing.Imaging.Encoder.Compression;
ep.Param[0] = new
EncoderParameter(eng,(long)EncoderValue.MultiFrame );
ep.Param[1] = new
EncoderParameter(eng1,(long)EncoderValue.Compressi onCCITT3);
ep.Param[2] = new
EncoderParameter(eng,(long)EncoderValue.FrameDimen sionPage);
EncoderParameters eps = new
EncoderParameters(2);

if (iCount 1)
{

File.Copy(outputFile,outputFile.Replace(OUTPUTFILE _EXT,OUTPUTFILERE_EXT)
);
return;
}
//Walk thru each page and compress and save to file
for(ix = 0; ix < iCount; ix++ )
{
//Need a start and ending image object
myImage.SelectActiveFrame( FrameDimension.Page, ix );
Bitmap img = (Bitmap) myImage.Clone();
ImageCodecInfo info = GetEncoderInfo("image/tiff");
bm=new
Bitmap(img.Width,img.Height,PixelFormat.Format1bpp Indexed);
//Need to lock the bitmap and read the pixels
BitmapData bmd=bm.LockBits(new Rectangle(0, 0, bm.Width,
bm.Height), ImageLockMode.ReadWrite, PixelFormat.Format1bppIndexed );
//Walk thru each row and colun and set the pixels to
either white or black monchrome
for(int y=0;y<img.Height;y++)
{
for(int x=0;x<img.Width;x++)
{
if(img.GetPixel(x,y).GetBrightness()>0.5f)
this.SetIndexedPixel(x,y,bmd,true);
}
}
//write the changed data to the image control
bm.UnlockBits(bmd);
if (ix == 0)
{
eps.Param[0] = new
EncoderParameter(System.Drawing.Imaging.Encoder.Sa veFlag,
(long)EncoderValue.MultiFrame);
eps.Param[1] = new
EncoderParameter(System.Drawing.Imaging.Encoder.Co mpression,
(long)EncoderValue.CompressionCCITT3);

bm.Save(outputFile.Replace(OUTPUTFILE_EXT,OUTPUTFI LERE_EXT),info,eps);
}
else
{
eps.Param[0] = new
EncoderParameter(System.Drawing.Imaging.Encoder.Sa veFlag,
(long)EncoderValue.FrameDimensionPage);
bm.SaveAdd(eps);
eps.Param[0] = new
EncoderParameter(System.Drawing.Imaging.Encoder.Sa veFlag,
(long)EncoderValue.Flush);
bm.SaveAdd(eps);
}
}
myImage.Dispose();
bm.Dispose();
GC.Collect();
}
catch(Exception e)
{
ErrorLg er = new ErrorLg();
er.LogErrorToDisk(e.Message.ToString(),"ACATSWinFa x" +
":CompressTIFF()",_path);
e = null;
er = null;
}
}
*** Sent via Developersdex http://www.developersdex.com ***
Jun 19 '07 #1
0 1861

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: malcolm | last post by:
Hello, We have a small team building a project that involves some 30 or so c# assembly dlls. It is a client server application with 1 exe as the starting point. The dlls and exe are sharing an...
7
by: | last post by:
I fail to understand why that the memory allocated in the void create(int **matrix) does not remain. I passed the address of matrix so shouldn't it still have the allocated memory when it returns...
0
by: mitchellguzman | last post by:
Some of the code is below, when I change the EncoderValue.CompressionCCITT3 to EncoderValue.CompressionLZW it works fine. The error message is the generic error "Invalid parameter used.", I...
11
by: Jeff Robichaud | last post by:
Are there any security issues having the ASPNET user account member of Administrators ? Is it a good practice ?
6
by: Ken Varn | last post by:
I have an ASP.NET application that is calling a custom class that is trying to parse all of the members of my Page object using Type.GetMembers(). The problem that I am having is that private...
7
by: Andrew Christiansen | last post by:
Hey everyone. I have Visual Basic .NET 2003 and am trying to show images on a treeview control. I have the imagelist on the form filled with images, and have the ImageList property of the...
0
by: just.starting | last post by:
I am having problem while downloading files from an apache server2.0.53 with php4.3.10.While downloading some files it generally stops after downloading some specific amount and then stops...
3
by: =?Utf-8?B?QXhlbCBEYWhtZW4=?= | last post by:
Hi, we've got a strange problem here: We've created an ASP.NET 2.0 web application using Membership.ValidateUser() to manually authenticate users with our website. The problem is: If the...
4
by: muddy22 | last post by:
I'm only having a problem with a small part, i'm fairly new to computer programming and the program i'm using is Dev-C++. The part that i'm having a problem with is this: int WINAPI WinMain...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.