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,603 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 Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

746 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

13 Experts available now in Live!

Get 1:1 Help Now