Solved

System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+ (cannot do Image.save after server switch).

Posted on 2010-11-15
4
1,649 Views
Last Modified: 2012-05-10
I have a web application that is using image.save to update graphics and save it back to the disk. However, after switching from server 2003 to 2008 R2(IIS 7.5), it stopped working, and gives me the old "System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+ ". After research, I've tried several solutions which usually fixes it, but they don't work. Here is what I've tried.
1. Add IIS AppPool\DefaultAppPool and give it write access, that should allow anonymous user to write to disk.
2. add graphic.dispose() and Image.dispose() as given by MS kb article, it didn't work.

Can anyone help? my code is like this.
 Dim Image1 As System.Drawing.Image = System.Drawing.Image.FromFile(Server.MapPath("images/1.jpg"))

            Dim oGraphic As Graphics = Graphics.FromImage(Image1)
        
            Dim oColor As System.Drawing.Color = Color.Black
            Dim sText As String = Request.QueryString("username")
            Dim dateText As String = DateTime.Now.Date
            Dim oBrush As New SolidBrush(Color.White) 'background
            Dim oBrushWrite As New SolidBrush(Color.Black) 'text
            oGraphic.FillRectangle(oBrush, 668, 600, 468, 60)
            Dim oFont As New Font("Arial", 24)
            Dim oPoint As New PointF(450.0F, 280.0F)
            oGraphic.DrawString(sText, oFont, oBrushWrite, oPoint)
            oGraphic.DrawString(dateText, oFont, oBrushWrite, New PointF(450.0F, 500.0F))
     
            Image1.Save(Server.MapPath("gen_img2.jpg"), ImageFormat.Jpeg)
            oGraphic.Dispose()
            Image1.Dispose()

Open in new window

0
Comment
Question by:ffayyca1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 7

Expert Comment

by:niralshah
ID: 34142779
0
 
LVL 1

Accepted Solution

by:
ffayyca1 earned 500 total points
ID: 34144879
I renamed the output file, and that worked.
0
 
LVL 7

Expert Comment

by:niralshah
ID: 34144910
You have found solution from the link i have sent you. So you should accept my solution as your answer.

Thanks
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…

742 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question