Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Invalid Parameter Used. at System.Drawing.Image.Save

328 views
Skip to first unread message

Prasad More

unread,
Apr 22, 2005, 5:45:02 AM4/22/05
to
Hello,
I am trying to write a text on Multi-page TIFF image using C# and .NET GDI+. I have written following code to do this. When I execute this code I get "Invalid Parameter User. at System.Drawing.Image.Save" error.

public void addAnnotationStampOnImage()
{
string strStamp = Path.GetFileNameWithoutExtension(_ImageFileName);
Size dSize;
Image iMulti = Image.FromFile(_ImageFileName);
Font Fnt;
string [] FontColor;
FontStyle FntStyle;
float FontSize, LeftPos, TopPos;
string FontName, FontColors;
int intPageCount, intP;
EncoderParameters encParamsCompress, encParamsMulti, encParamsAddFrame, encParamsCloseFrame;
Encoder encCompress, encSave;
encParamsCompress = new EncoderParameters(1);
encParamsMulti = new EncoderParameters(2);
encParamsAddFrame = new EncoderParameters(1);
encParamsCloseFrame = new EncoderParameters(1);
encCompress = new Encoder(Encoder.Compression.Guid);
encSave = new Encoder(Encoder.SaveFlag.Guid);

encParamsCompress.Param[0] = new EncoderParameter(encCompress, (long)EncoderValue.CompressionCCITT4);
encParamsMulti.Param[0] = new EncoderParameter(encSave, (long)EncoderValue.MultiFrame);
encParamsMulti.Param[1] = new EncoderParameter(encCompress, (long)EncoderValue.CompressionCCITT4);
encParamsAddFrame.Param[0] = new EncoderParameter(encSave, (long)EncoderValue.FrameDimensionPage);
encParamsCloseFrame.Param[0] = new EncoderParameter(encSave, (long)EncoderValue.Flush);

FrameDimension oFDimensionM = new FrameDimension(iMulti.FrameDimensionsList[0]);
intPageCount = iMulti.GetFrameCount(oFDimensionM);

dSize = new Size(iMulti.Width, iMulti.Height);

iMulti.SelectActiveFrame(oFDimensionM, 0);
Bitmap iICN = new Bitmap(iMulti, dSize);
Graphics gImage = Graphics.FromImage(iICN);
FontSize = 28F;
FontName = "Microsoft Sans Serif";
FntStyle = FontStyle.Italic;
FontColors = "00,00,00";
FontColor = FontColors.Split(",".ToCharArray());
Fnt = new Font(FontName, FontSize, FntStyle);
TopPos = 10.0F;
LeftPos = 650.0F;
gImage.DrawString(strStamp, Fnt, new SolidBrush(Color.FromArgb(Convert.ToInt32(FontColor[0]), Convert.ToInt32(FontColor[1]), Convert.ToInt32(FontColor[2]))), new PointF(LeftPos, TopPos));
iICN.Save(_ImageFileName.Replace(".", "temp."), GetEncoderInfo("image/tiff"), encParamsCompress);
for (intP = 1; intP < intPageCount; intP++)
{
iMulti.SelectActiveFrame(oFDimensionM, intP);
iICN.SaveAdd(iMulti, encParamsAddFrame);
}
iICN.SaveAdd(encParamsCloseFrame);
iICN.Dispose();
}


If I change the above function to use
iICN.Save(_ImageFileName.Replace(".", "temp."), ImageFormat.Tiff); instead of
iICN.Save(_ImageFileName.Replace(".", "temp."), GetEncoderInfo("image/tiff"), encParamsCompress); then I get the following " a generic error occurred in GDI+. at System.Drawing.Image.SaveAdd.

Please help.

Prasad


From http://www.developmentnow.com/g/20_2005_2_0_0_0/dotnet-framework-drawing.htm

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com

Bob Powell [MVP]

unread,
Apr 22, 2005, 9:21:14 AM4/22/05
to
CCITT4 compression only works on 1 bit per pixel fax type files.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Prasad More" <pra...@entech.us> wrote in message
news:9c41e04f-8e5f-47bb...@msnews.microsoft.com...

Prasad More

unread,
Apr 27, 2005, 1:09:51 AM4/27/05
to
I didn't get you. Can you please explain me what do I need to
modify in my program so that it works.

Best Regards,
Prasad
--
POST BY: http://www.dotNET.us - Need .NET? Just ask, Please dotNET.us

a tocco

unread,
Apr 30, 2005, 2:48:41 AM4/30/05
to
I usually get that error when the bitmap im trying to save is disposed.

Are you calling Bitmap.dispose anywhere before calling this?


"Prasad More" <pra...@entech.us> wrote in message

news:eUeqYduS...@TK2MSFTNGP10.phx.gbl...

Sonali Jagtap

unread,
Feb 23, 2006, 4:01:30 AM2/23/06
to
Hi Bob,

I am also getting the same error.

My first frame with Encoder parameter

ep.Param[0] = new EncoderParameter(Encoder.SaveFlag,(long)EncoderValue.
MultiFrame);
ep.Param[1] = new EncoderParameter(Encoder.Compression,(long)System.Drawing.
Imaging.EncoderValue.CompressionCCITT4);

is saved properly but facing the same error when i try to saveadd another
frame with Encoder Param[0] = ep.Param[0]=new EncoderParameter(Encoder.
SaveFlag,(long)EncoderValue.FrameDimensionPage);

and Param[1] same as above...

( written the code referring ur FAQ http://www.bobpowell.net/onebit.htm )

Please reply ...

Thanks..

0 new messages