Generic Error in GDI+

  • Thread starter Thread starter Alphonse Giambrone
  • Start date Start date
A

Alphonse Giambrone

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.ExternalException: A
generic error occurred in GDI+.

Source Error:


Line 76: .DrawString(Text, fnt, New SolidBrush(Color.White), 0, 0)
Line 77:
Line 78: bmp.Save(Path, System.Drawing.Imaging.ImageFormat.Gif)
Line 79: m_iHeight = bmp.Height
Line 80: m_iWidth = bmp.Width


Source File: D:\Inetpub\wwwroot\Chapter04\ImageCreation.aspx.vb Line: 78

Stack Trace:


[ExternalException (0x80004005): A generic error occurred in GDI+.]
System.Drawing.Image.Save(String filename, ImageCodecInfo encoder,
EncoderParameters encoderParams) +582
System.Drawing.Image.Save(String filename, ImageFormat format) +61
Chapter_04.ImageCreation.CreateImage(String Text, String& Path) in
D:\Inetpub\wwwroot\Chapter04\ImageCreation.aspx.vb:78
Chapter_04.ImageCreation.inimgGo_ServerClick(Object sender,
ImageClickEventArgs e) in
D:\Inetpub\wwwroot\Chapter04\ImageCreation.aspx.vb:40

System.Web.UI.HtmlControls.HtmlInputImage.OnServerClick(ImageClickEventArgs
e) +109

System.Web.UI.HtmlControls.HtmlInputImage.System.Web.UI.IPostBackEventHandle
r.RaisePostBackEvent(String eventArgument) +67
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1277





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

Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET
Version:1.1.4322.573

--

Here is the full code for the routine:
Private Sub CreateImage(ByVal 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.FromImage(dummy)

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

gfx.Dispose()

dummy = Nothing

Dim bmp As Bitmap = New Bitmap(CInt(size.Width), CInt(size.Height))

gfx = Graphics.FromImage(bmp)

With gfx

..CompositingQuality = Drawing.Drawing2D.CompositingQuality.HighQuality

..InterpolationMode = Drawing.Drawing2D.InterpolationMode.HighQualityBicubic

..SmoothingMode = Drawing.Drawing2D.SmoothingMode.HighQuality

..TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias

..FillRectangle( _

New Drawing2D.LinearGradientBrush( _

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

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

Color.Red, _

Color.Black), _

0, 0, CInt(size.Width), CInt(size.Height))

..DrawString(Text, fnt, New SolidBrush(Color.White), 0, 0)

bmp.Save(Path, System.Drawing.Imaging.ImageFormat.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: (e-mail address removed)
For email replace NOSPAM with agiam
 
Instead of using the Overloaded method
System.Drawing.Image.Save(String, System.Drawing.Imaging.ImageFormat.Jpeg);

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

System.Drawing.Image.Save(System.IO.FileStream,
System.Drawing.Imaging.ImageFormat.Jpeg);

or

System.Drawing.Image.Save(System.IO.MemoryStream,
System.Drawing.Imaging.ImageFormat.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 said:
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.ExternalException: A
generic error occurred in GDI+.

Source Error:


Line 76: .DrawString(Text, fnt, New SolidBrush(Color.White), 0, 0)
Line 77:
Line 78: bmp.Save(Path, System.Drawing.Imaging.ImageFormat.Gif)
Line 79: m_iHeight = bmp.Height
Line 80: m_iWidth = bmp.Width


Source File: D:\Inetpub\wwwroot\Chapter04\ImageCreation.aspx.vb Line: 78

Stack Trace:


[ExternalException (0x80004005): A generic error occurred in GDI+.]
System.Drawing.Image.Save(String filename, ImageCodecInfo encoder,
EncoderParameters encoderParams) +582
System.Drawing.Image.Save(String filename, ImageFormat format) +61
Chapter_04.ImageCreation.CreateImage(String Text, String& Path) in
D:\Inetpub\wwwroot\Chapter04\ImageCreation.aspx.vb:78
Chapter_04.ImageCreation.inimgGo_ServerClick(Object sender,
ImageClickEventArgs e) in
D:\Inetpub\wwwroot\Chapter04\ImageCreation.aspx.vb:40

System.Web.UI.HtmlControls.HtmlInputImage.OnServerClick(ImageClickEventArgs
e) +109

System.Web.UI.HtmlControls.HtmlInputImage.System.Web.UI.IPostBackEventHandle
r.RaisePostBackEvent(String eventArgument) +67
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1277





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

Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET
Version:1.1.4322.573

--

Here is the full code for the routine:
Private Sub CreateImage(ByVal 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.FromImage(dummy)

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

gfx.Dispose()

dummy = Nothing

Dim bmp As Bitmap = New Bitmap(CInt(size.Width), CInt(size.Height))

gfx = Graphics.FromImage(bmp)

With gfx

.CompositingQuality = Drawing.Drawing2D.CompositingQuality.HighQuality

.InterpolationMode = Drawing.Drawing2D.InterpolationMode.HighQualityBicubic

.SmoothingMode = Drawing.Drawing2D.SmoothingMode.HighQuality

.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias

.FillRectangle( _

New Drawing2D.LinearGradientBrush( _

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

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

Color.Red, _

Color.Black), _

0, 0, CInt(size.Width), CInt(size.Height))

.DrawString(Text, fnt, New SolidBrush(Color.White), 0, 0)

bmp.Save(Path, System.Drawing.Imaging.ImageFormat.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: (e-mail address removed)
For email replace NOSPAM with agiam
 
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: (e-mail address removed)
For email replace NOSPAM with agiam


Mark Miller said:
Instead of using the Overloaded method
System.Drawing.Image.Save(String, System.Drawing.Imaging.ImageFormat.Jpeg);

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

System.Drawing.Image.Save(System.IO.FileStream,
System.Drawing.Imaging.ImageFormat.Jpeg);

or

System.Drawing.Image.Save(System.IO.MemoryStream,
System.Drawing.Imaging.ImageFormat.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 said:
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.ExternalException: A
generic error occurred in GDI+.

Source Error:


Line 76: .DrawString(Text, fnt, New SolidBrush(Color.White), 0, 0)
Line 77:
Line 78: bmp.Save(Path, System.Drawing.Imaging.ImageFormat.Gif)
Line 79: m_iHeight = bmp.Height
Line 80: m_iWidth = bmp.Width


Source File: D:\Inetpub\wwwroot\Chapter04\ImageCreation.aspx.vb Line: 78

Stack Trace:


[ExternalException (0x80004005): A generic error occurred in GDI+.]
System.Drawing.Image.Save(String filename, ImageCodecInfo encoder,
EncoderParameters encoderParams) +582
System.Drawing.Image.Save(String filename, ImageFormat format) +61
Chapter_04.ImageCreation.CreateImage(String Text, String& Path) in
D:\Inetpub\wwwroot\Chapter04\ImageCreation.aspx.vb:78
Chapter_04.ImageCreation.inimgGo_ServerClick(Object sender,
ImageClickEventArgs e) in
D:\Inetpub\wwwroot\Chapter04\ImageCreation.aspx.vb:40
System.Web.UI.HtmlControls.HtmlInputImage.OnServerClick(ImageClickEventArgs
System.Web.UI.HtmlControls.HtmlInputImage.System.Web.UI.IPostBackEventHandle
r.RaisePostBackEvent(String eventArgument) +67
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1277





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

Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET
Version:1.1.4322.573

--

Here is the full code for the routine:
Private Sub CreateImage(ByVal 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.FromImage(dummy)

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

gfx.Dispose()

dummy = Nothing

Dim bmp As Bitmap = New Bitmap(CInt(size.Width), CInt(size.Height))

gfx = Graphics.FromImage(bmp)

With gfx

.CompositingQuality = Drawing.Drawing2D.CompositingQuality.HighQuality

.InterpolationMode = Drawing.Drawing2D.InterpolationMode.HighQualityBicubic

.SmoothingMode = Drawing.Drawing2D.SmoothingMode.HighQuality

.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias

.FillRectangle( _

New Drawing2D.LinearGradientBrush( _

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

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

Color.Red, _

Color.Black), _

0, 0, CInt(size.Width), CInt(size.Height))

.DrawString(Text, fnt, New SolidBrush(Color.White), 0, 0)

bmp.Save(Path, System.Drawing.Imaging.ImageFormat.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: (e-mail address removed)
For email replace NOSPAM with agiam
 
Back
Top