473,692 Members | 3,082 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Generic Error in GDI+

I am currently reading 'Programming The Web with Visual Basic .NET' and
have so far found it to be excellent. Downloaded all the code from Apress
and working in chapter 4, I get the error shown below.
I am running IIS5 on WinXP Pro.
Server Error in '/Chapter04' Application.
----------------------------------------------------------------------------
----

A generic error occurred in GDI+.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Runtime. InteropServices .ExternalExcept ion: A
generic error occurred in GDI+.

Source Error:
Line 76: .DrawString(Tex t, fnt, New SolidBrush(Colo r.White), 0, 0)
Line 77:
Line 78: bmp.Save(Path, System.Drawing. Imaging.ImageFo rmat.Gif)
Line 79: m_iHeight = bmp.Height
Line 80: m_iWidth = bmp.Width
Source File: D:\Inetpub\wwwr oot\Chapter04\I mageCreation.as px.vb Line: 78

Stack Trace:
[ExternalExcepti on (0x80004005): A generic error occurred in GDI+.]
System.Drawing. Image.Save(Stri ng filename, ImageCodecInfo encoder,
EncoderParamete rs encoderParams) +582
System.Drawing. Image.Save(Stri ng filename, ImageFormat format) +61
Chapter_04.Imag eCreation.Creat eImage(String Text, String& Path) in
D:\Inetpub\wwwr oot\Chapter04\I mageCreation.as px.vb:78
Chapter_04.Imag eCreation.inimg Go_ServerClick( Object sender,
ImageClickEvent Args e) in
D:\Inetpub\wwwr oot\Chapter04\I mageCreation.as px.vb:40

System.Web.UI.H tmlControls.Htm lInputImage.OnS erverClick(Imag eClickEventArgs
e) +109

System.Web.UI.H tmlControls.Htm lInputImage.Sys tem.Web.UI.IPos tBackEventHandl e
r.RaisePostBack Event(String eventArgument) +67
System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData) +33
System.Web.UI.P age.ProcessRequ estMain() +1277

----------------------------------------------------------------------------
----

Version Information: Microsoft .NET Framework Version:1.1.432 2.573; ASP.NET
Version:1.1.432 2.573

--

Here is the full code for the routine:
Private Sub CreateImage(ByV al Text As String, _

ByRef Path As String)

Dim fnt As New Font("Verdana", 40)

Dim dummy As Bitmap = New Bitmap(1, 1)

Dim gfx As Graphics = Graphics.FromIm age(dummy)

Dim size As SizeF = gfx.MeasureStri ng(Text, fnt)

gfx.Dispose()

dummy = Nothing

Dim bmp As Bitmap = New Bitmap(CInt(siz e.Width), CInt(size.Heigh t))

gfx = Graphics.FromIm age(bmp)

With gfx

..CompositingQu ality = Drawing.Drawing 2D.CompositingQ uality.HighQual ity

..Interpolation Mode = Drawing.Drawing 2D.Interpolatio nMode.HighQuali tyBicubic

..SmoothingMode = Drawing.Drawing 2D.SmoothingMod e.HighQuality

..TextRendering Hint = Drawing.Text.Te xtRenderingHint .AntiAlias

..FillRectangle ( _

New Drawing2D.Linea rGradientBrush( _

New Point(0, CInt(size.Heigh t) - 1), _

New Point(CInt(size .Width) - 1, 0), _

Color.Red, _

Color.Black), _

0, 0, CInt(size.Width ), CInt(size.Heigh t))

..DrawString(Te xt, fnt, New SolidBrush(Colo r.White), 0, 0)

bmp.Save(Path, System.Drawing. Imaging.ImageFo rmat.Gif)

m_iHeight = bmp.Height

m_iWidth = bmp.Width

..Dispose()

End With

End Sub

Can anyone point me to a cause/fix??

Any help would be appreciated.
Alphonse Giambrone
Email: NO****@customda tasolutions.us
For email replace NOSPAM with agiam

Nov 17 '05 #1
2 22303
Instead of using the Overloaded method
System.Drawing. Image.Save(Stri ng, System.Drawing. Imaging.ImageFo rmat.Jpeg);

depending on what you want to do use one of the following:

System.Drawing. Image.Save(Syst em.IO.FileStrea m,
System.Drawing. Imaging.ImageFo rmat.Jpeg);

or

System.Drawing. Image.Save(Syst em.IO.MemoryStr eam,
System.Drawing. Imaging.ImageFo rmat.Jpeg);

Apparently from ASP.Net you will get this error when you are using a file
path as a string. If this does not solve your problem then look at security
issues. The ASPNET useraccount may not have permissions to write to disk.

"Alphonse Giambrone" <NO*********@cu stomdatasolutio ns.us> wrote in message
news:uk******** ******@TK2MSFTN GP10.phx.gbl...
I am currently reading 'Programming The Web with Visual Basic .NET' and
have so far found it to be excellent. Downloaded all the code from Apress
and working in chapter 4, I get the error shown below.
I am running IIS5 on WinXP Pro.
Server Error in '/Chapter04' Application.
-------------------------------------------------------------------------- -- ----

A generic error occurred in GDI+.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Runtime. InteropServices .ExternalExcept ion: A
generic error occurred in GDI+.

Source Error:
Line 76: .DrawString(Tex t, fnt, New SolidBrush(Colo r.White), 0, 0) Line 77:
Line 78: bmp.Save(Path, System.Drawing. Imaging.ImageFo rmat.Gif)
Line 79: m_iHeight = bmp.Height
Line 80: m_iWidth = bmp.Width
Source File: D:\Inetpub\wwwr oot\Chapter04\I mageCreation.as px.vb Line: 78
Stack Trace:
[ExternalExcepti on (0x80004005): A generic error occurred in GDI+.]
System.Drawing. Image.Save(Stri ng filename, ImageCodecInfo encoder,
EncoderParamete rs encoderParams) +582
System.Drawing. Image.Save(Stri ng filename, ImageFormat format) +61
Chapter_04.Imag eCreation.Creat eImage(String Text, String& Path) in
D:\Inetpub\wwwr oot\Chapter04\I mageCreation.as px.vb:78
Chapter_04.Imag eCreation.inimg Go_ServerClick( Object sender,
ImageClickEvent Args e) in
D:\Inetpub\wwwr oot\Chapter04\I mageCreation.as px.vb:40

System.Web.UI.H tmlControls.Htm lInputImage.OnS erverClick(Imag eClickEventArgs e) +109

System.Web.UI.H tmlControls.Htm lInputImage.Sys tem.Web.UI.IPos tBackEventHandl e r.RaisePostBack Event(String eventArgument) +67
System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData) +33
System.Web.UI.P age.ProcessRequ estMain() +1277

-------------------------------------------------------------------------- -- ----

Version Information: Microsoft .NET Framework Version:1.1.432 2.573; ASP.NET Version:1.1.432 2.573

--

Here is the full code for the routine:
Private Sub CreateImage(ByV al Text As String, _

ByRef Path As String)

Dim fnt As New Font("Verdana", 40)

Dim dummy As Bitmap = New Bitmap(1, 1)

Dim gfx As Graphics = Graphics.FromIm age(dummy)

Dim size As SizeF = gfx.MeasureStri ng(Text, fnt)

gfx.Dispose()

dummy = Nothing

Dim bmp As Bitmap = New Bitmap(CInt(siz e.Width), CInt(size.Heigh t))

gfx = Graphics.FromIm age(bmp)

With gfx

.CompositingQua lity = Drawing.Drawing 2D.CompositingQ uality.HighQual ity

.InterpolationM ode = Drawing.Drawing 2D.Interpolatio nMode.HighQuali tyBicubic
.SmoothingMode = Drawing.Drawing 2D.SmoothingMod e.HighQuality

.TextRenderingH int = Drawing.Text.Te xtRenderingHint .AntiAlias

.FillRectangle( _

New Drawing2D.Linea rGradientBrush( _

New Point(0, CInt(size.Heigh t) - 1), _

New Point(CInt(size .Width) - 1, 0), _

Color.Red, _

Color.Black), _

0, 0, CInt(size.Width ), CInt(size.Heigh t))

.DrawString(Tex t, fnt, New SolidBrush(Colo r.White), 0, 0)

bmp.Save(Path, System.Drawing. Imaging.ImageFo rmat.Gif)

m_iHeight = bmp.Height

m_iWidth = bmp.Width

.Dispose()

End With

End Sub

Can anyone point me to a cause/fix??

Any help would be appreciated.
Alphonse Giambrone
Email: NO****@customda tasolutions.us
For email replace NOSPAM with agiam

Nov 17 '05 #2
Mark,

Thanks for the quick response. I do need to save it as a file. At this stage
I am just trying to follow the book. My first thought was a permission
problem also and I went into IIS and enabled write permission for the
folder. The default user account was IUSR. I tried IWAM and ASPNET
(restarting IIS each time), still the same problem.
Any more ideas?

--

Alphonse Giambrone
Email: NO****@customda tasolutions.us
For email replace NOSPAM with agiam
"Mark Miller" <no**********@w aveshift.com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Instead of using the Overloaded method
System.Drawing. Image.Save(Stri ng, System.Drawing. Imaging.ImageFo rmat.Jpeg);
depending on what you want to do use one of the following:

System.Drawing. Image.Save(Syst em.IO.FileStrea m,
System.Drawing. Imaging.ImageFo rmat.Jpeg);

or

System.Drawing. Image.Save(Syst em.IO.MemoryStr eam,
System.Drawing. Imaging.ImageFo rmat.Jpeg);

Apparently from ASP.Net you will get this error when you are using a file
path as a string. If this does not solve your problem then look at security issues. The ASPNET useraccount may not have permissions to write to disk.

"Alphonse Giambrone" <NO*********@cu stomdatasolutio ns.us> wrote in message
news:uk******** ******@TK2MSFTN GP10.phx.gbl...
I am currently reading 'Programming The Web with Visual Basic .NET' and
have so far found it to be excellent. Downloaded all the code from Apress and working in chapter 4, I get the error shown below.
I am running IIS5 on WinXP Pro.
Server Error in '/Chapter04' Application.


--------------------------------------------------------------------------
--
----

A generic error occurred in GDI+.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Runtime. InteropServices .ExternalExcept ion: A
generic error occurred in GDI+.

Source Error:
Line 76: .DrawString(Tex t, fnt, New SolidBrush(Colo r.White), 0,

0)
Line 77:
Line 78: bmp.Save(Path, System.Drawing. Imaging.ImageFo rmat.Gif)
Line 79: m_iHeight = bmp.Height
Line 80: m_iWidth = bmp.Width
Source File: D:\Inetpub\wwwr oot\Chapter04\I mageCreation.as px.vb Line:

78

Stack Trace:
[ExternalExcepti on (0x80004005): A generic error occurred in GDI+.]
System.Drawing. Image.Save(Stri ng filename, ImageCodecInfo encoder,
EncoderParamete rs encoderParams) +582
System.Drawing. Image.Save(Stri ng filename, ImageFormat format) +61
Chapter_04.Imag eCreation.Creat eImage(String Text, String& Path) in
D:\Inetpub\wwwr oot\Chapter04\I mageCreation.as px.vb:78
Chapter_04.Imag eCreation.inimg Go_ServerClick( Object sender,
ImageClickEvent Args e) in
D:\Inetpub\wwwr oot\Chapter04\I mageCreation.as px.vb:40

System.Web.UI.H tmlControls.Htm lInputImage.OnS erverClick(Imag eClickEventArgs
e) +109

System.Web.UI.H tmlControls.Htm lInputImage.Sys tem.Web.UI.IPos tBackEventHandl e
r.RaisePostBack Event(String eventArgument) +67
System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData) +33 System.Web.UI.P age.ProcessRequ estMain() +1277



--------------------------------------------------------------------------
--
----

Version Information: Microsoft .NET Framework Version:1.1.432 2.573;

ASP.NET
Version:1.1.432 2.573

--

Here is the full code for the routine:
Private Sub CreateImage(ByV al Text As String, _

ByRef Path As String)

Dim fnt As New Font("Verdana", 40)

Dim dummy As Bitmap = New Bitmap(1, 1)

Dim gfx As Graphics = Graphics.FromIm age(dummy)

Dim size As SizeF = gfx.MeasureStri ng(Text, fnt)

gfx.Dispose()

dummy = Nothing

Dim bmp As Bitmap = New Bitmap(CInt(siz e.Width), CInt(size.Heigh t))

gfx = Graphics.FromIm age(bmp)

With gfx

.CompositingQua lity = Drawing.Drawing 2D.CompositingQ uality.HighQual ity

.InterpolationM ode =

Drawing.Drawing 2D.Interpolatio nMode.HighQuali tyBicubic

.SmoothingMode = Drawing.Drawing 2D.SmoothingMod e.HighQuality

.TextRenderingH int = Drawing.Text.Te xtRenderingHint .AntiAlias

.FillRectangle( _

New Drawing2D.Linea rGradientBrush( _

New Point(0, CInt(size.Heigh t) - 1), _

New Point(CInt(size .Width) - 1, 0), _

Color.Red, _

Color.Black), _

0, 0, CInt(size.Width ), CInt(size.Heigh t))

.DrawString(Tex t, fnt, New SolidBrush(Colo r.White), 0, 0)

bmp.Save(Path, System.Drawing. Imaging.ImageFo rmat.Gif)

m_iHeight = bmp.Height

m_iWidth = bmp.Width

.Dispose()

End With

End Sub

Can anyone point me to a cause/fix??

Any help would be appreciated.
Alphonse Giambrone
Email: NO****@customda tasolutions.us
For email replace NOSPAM with agiam


Nov 17 '05 #3

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

Similar topics

4
48222
by: Michael Kennedy [UB] | last post by:
Hi Everyone, I have this multithreaded C# windows forms application which does a lot of image processing. Occasionally, I get the following error: A generic error occurred in GDI+. System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+. at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams)
3
5868
by: T. Davis | last post by:
In C#, I am able to successfully stream a TIFF image that comes from a BLOB field in a database, save it to file, then convert the pages within TIFF file into jpegs (using GDI+) and display on the web (using ASP.NET). However, when I generate the Image object using FromStream (passing in the MemoryStream containing image bytes), an exception of "A generic error occurred in GDI+" is thrown when performing the conversion/save for display....
13
4655
by: lgbjr | last post by:
Hello All, I have some pictureboxes on a VB.NET form that are linked to an AccessDB. If the user wishes to open or edit an image, I need to save the image in the picturebox to a temp file, then open that file in whatever viewer/editor is the default for the users system. I tried to do picturebox1.image.save(filename), which results in "A Generic error occured in GDI+". However, if I use an unbound picturebox, do a
15
5341
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the path of the uploaded image, and resize it with the provided dimensions. My function is below. The current function is returning an error when run from the upload function: A generic error occurred in GDI+. Not sure what exactly that means. From what...
0
1241
by: James Wong | last post by:
Hi everybody, I'm facing a serious trouble relating to GDI+ generic error. The error message is "A Generic error occured in GDI+" and the following information is stored in Excepton object: System.Drawing.Graphics.CheckErrorStatus(Int32 status) System.Drawing.Graphics.DrawString(String s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format) System.Drawing.Graphics.DrawString(String s, Font font, Brush brush, PointF...
14
4104
by: James Wong | last post by:
Hi everybody, I'm facing a serious trouble relating to GDI+ generic error. The error message is "A Generic error occured in GDI+" and the following information is stored in Excepton object: System.Drawing.Graphics.CheckErrorStatus(Int32 status) System.Drawing.Graphics.DrawString(String s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format) System.Drawing.Graphics.DrawString(String s, Font font, Brush brush, PointF...
0
1394
by: manini | last post by:
Hello Everyone I m getting the generic GDI + error,Please help me to resolve this error ************** Exception Text ************** System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+. at System.Drawing.Graphics.CheckErrorStatus(Int32 status) at System.Drawing.Graphics.DrawString(String s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format) at...
7
10387
by: j4richard | last post by:
Help please, I am getting this "Unhandled Exception has occurred in your application" " A Generic error occurred in GDI+" See the end of this message for details on invoking just-in-time (JIT) debugging instead of this dialog box. ************** Exception Text ************** System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+.
1
3984
by: Jeff | last post by:
hi asp.net 2.0 I'm experimenting with GDI+ in asp.net and get an "A generic error occurred in GDI+." exception. Below is my code, I've marked a line with "<<<<-- here". It's here the exception is thrown.
0
8611
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9100
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8812
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7643
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5824
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4332
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4565
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2989
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2245
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.