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

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

Yametazamwa mara 342
Ruka hadi kwenye ujumbe wa kwanza ambao haujasomwa

Prasad More

hayajasomwa,
22 Apr 2005, 05:45:0222/04/2005
kwa
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]

hayajasomwa,
22 Apr 2005, 09:21:1422/04/2005
kwa
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

hayajasomwa,
27 Apr 2005, 01:09:5127/04/2005
kwa
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

hayajasomwa,
30 Apr 2005, 02:48:4130/04/2005
kwa
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

hayajasomwa,
23 Feb 2006, 04:01:3023/02/2006
kwa
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..

Ujumbe 0 mpya