469,904 Members | 2,452 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,904 developers. It's quick & easy.

edit multi-page tiff image using C# and .NET GDI+

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(FontColo r[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

Nov 17 '05 #1
1 15836
I answered this over in the drawing newsgroup.

--
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" <Prasad Mo**@discussions.microsoft.com> wrote in message
news:84**********************************@microsof t.com...
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(FontColo r[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

Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Konrad L. M. Rudolph | last post: by
1 post views Thread by Mark | last post: by
1 post views Thread by Paul Fredlein | last post: by
reply views Thread by =?Utf-8?B?UnVpIE9saXZlaXJh?= | last post: by
1 post views Thread by =?Utf-8?B?UnVpIE9saXZlaXJh?= | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.