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,612 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Handle null when using linq in this line 1 26
Class object 2 26
Angular JS Route 3 50
ASP.net Run 3 sliders vertically as opposed to horizontally 9 19
AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

910 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now