Solved

A generic error occurred in GDI+. Bitmap.Save

Posted on 2013-01-16
6
1,602 Views
Last Modified: 2013-01-17
Hi Experts,

I have a console app that tries to save an image from a local directory to a UNC Path (Shared Folder on a Network Drive).

I am able to do save it without any issues on another local folder, but not to the Shared drive.

I get the error "A generic error occurred in GDI+." of an ExternalException.

Your help would be appreciated
0
Comment
Question by:InquisitiveMind
[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
  • 3
  • 2
6 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 38785271
Are you running the application as a user who has permissions to the share?
0
 

Author Comment

by:InquisitiveMind
ID: 38785288
@kaufmed:

I do not have an app.config for now. But yes I did try giving my credentials as

<system.web>
    <identity impersonate="true" userName="domain\myUserName" password="xxxxx"/>
  </system.web>

But my application is a console application. So, that wouldn't work.
0
 
LVL 9

Accepted Solution

by:
sognoct earned 500 total points
ID: 38786763
destroy the bitmap after save then redeclare it

Bitmap bm = new Bitmap(mypath);
bm.Save("Shared Folder\\out.bmp" ,System.Drawing.Imaging.ImageFormat.Bmp );
bm .dispose();
bm = null;

or you can save a temporary file on local folder then copy it to the shared drive (safer solution)
0
Give Your Engineering Team a Productivity Boost

Learn why container technology is so powerful and how it can provide your team with productivity gains and other benefits.

 

Author Comment

by:InquisitiveMind
ID: 38788739
@sognoct:

The error occurs exactly at the line where I call the Save method. I am also calling the Dispose() method as suggested by you and still get the error. Any other ideas?
0
 
LVL 9

Assisted Solution

by:sognoct
sognoct earned 500 total points
ID: 38789325
just for debugging try to save to local folder...

string appPath = Path.GetDirectoryName(Application.ExecutablePath);
string tempbmp = appPath + "\\out.bmp"
bm.Save(tempbmp ,System.Drawing.Imaging.ImageFormat.Bmp );
bm .dispose();
bm = null;
io.file.copy(tempbmp, "\\\\sharedfolder\\" + filename; 
 

Open in new window


if it throws io error maybe is a permission issue ... if it is still GDI error, there is another possibility. In fact Bitmap cause GDI error if it is originated by a filestream and the filestream has been closed.
In this case must create a new bitmap objects that has not a closed filestream. So if bm is the original bitmap:

      //create temporary
      Image t=new Bitmap(bm.Width,bm.Height);
      //get graphics
      Graphics g=Graphics.FromImage(t);
      //copy original
      g.DrawImage(bm,0,0);
      //close original
      i.Dispose();
      //Can now save
      t.Save(path)

Open in new window

0
 

Author Closing Comment

by:InquisitiveMind
ID: 38789580
Thanks guys. The temporary file solution worked for me.
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

636 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