473,406 Members | 2,281 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,406 software developers and data experts.

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 16201
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: * ProteanThread * | last post by:
but depends upon the clique: ...
5
by: Konrad L. M. Rudolph | last post by:
I hope this is the right NG, please notify me if not. I have got a problem with the "recent files" list of the start page in VS.NET: yesterday I created a new projekt which has the same name as...
4
by: mimmo | last post by:
Hi! I should convert the accented letters of a string in the correspondent letters not accented. But when I compile with -Wall it give me: warning: multi-character character constant Do the...
1
by: Mark | last post by:
Hi, I have used the following solution: http://support.microsoft.com/default.aspx?scid=kb;en-us;819398 The application works perfect but I would like to extend its capabilities. I need to...
1
by: Paul Fredlein | last post by:
Hi, Is there a simple way to print the contents of a multi line edit field? Just unformatted text with CRLF. Thanks, Paul
2
by: abc my vclass | last post by:
I want to write a form control to lookup some tables fields from database, let users to select one record (or multi-select more records) under win-form environment for fill some fields of parent...
1
by: mknoll217 | last post by:
I am recieving this error from my code: The multi-part identifier "PAR.UniqueID" could not be bound. The multi-part identifier "Salary.UniqueID" could not be bound. The multi-part identifier...
0
by: dan | last post by:
Hi, I have a multi-line textbox in a gridview when in edit mode. The textbox (rendered as textarea in browser) set cols to 20 by default. I'd like the textbox to 'adjust' itself to the width...
0
by: =?Utf-8?B?UnVpIE9saXZlaXJh?= | last post by:
Multi value in edit control separated by ; I want have multivalue behaviour in an edit control. Some similar to a list of email in Outlook, that are automatically underlined when insert a...
1
by: =?Utf-8?B?UnVpIE9saXZlaXJh?= | last post by:
Multi value in edit control separated by ; I want have multivalue behaviour in an edit control. Some similar to a list of email in Outlook, that are automatically underlined when insert a...
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: 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.