469,917 Members | 1,610 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

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.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(Objec t sender,
ImageClickEventArgs e) in
D:\Inetpub\wwwroot\Chapter04\ImageCreation.aspx.vb :40

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

System.Web.UI.HtmlControls.HtmlInputImage.System.W eb.UI.IPostBackEventHandle
r.RaisePostBackEvent(String eventArgument) +67
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection 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.HighQualityBic ubic

..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: NO****@customdatasolutions.us
For email replace NOSPAM with agiam

Nov 17 '05 #1
2 22024
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" <NO*********@customdatasolutions.us> wrote in message
news:uk**************@TK2MSFTNGP10.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.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(Objec t sender,
ImageClickEventArgs e) in
D:\Inetpub\wwwroot\Chapter04\ImageCreation.aspx.vb :40

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

System.Web.UI.HtmlControls.HtmlInputImage.System.W eb.UI.IPostBackEventHandle r.RaisePostBackEvent(String eventArgument) +67
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection 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.HighQualityBic ubic
.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: NO****@customdatasolutions.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****@customdatasolutions.us
For email replace NOSPAM with agiam
"Mark Miller" <no**********@waveshift.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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" <NO*********@customdatasolutions.us> wrote in message
news:uk**************@TK2MSFTNGP10.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.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(Objec t sender,
ImageClickEventArgs e) in
D:\Inetpub\wwwroot\Chapter04\ImageCreation.aspx.vb :40

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

System.Web.UI.HtmlControls.HtmlInputImage.System.W eb.UI.IPostBackEventHandle
r.RaisePostBackEvent(String eventArgument) +67
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection 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.HighQualityBic ubic

.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: NO****@customdatasolutions.us
For email replace NOSPAM with agiam


Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Michael Kennedy [UB] | last post: by
reply views Thread by James Wong | last post: by
14 posts views Thread by James Wong | last post: by
reply views Thread by manini | last post: by
1 post views Thread by Jeff | 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.