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,627 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
  • 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

830 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