Click here to Skip to main content
15,882,329 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I am getting an Generic Error in GDI+ while executing this code set.

Please Help..

I am using this code,

C#
private void btn_Send_Click(object sender, EventArgs e)
       {
           Rectangle bounds = this.Bounds;
           using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
           {
               using (Graphics g = Graphics.FromImage(bitmap))
               {

                   g.CopyFromScreen(new Point(bounds.Left, bounds.Top), Point.Empty, bounds.Size);
               }
               bitmap.Save("C://test.jpg",ImageFormat.Jpeg);
           }
       }
Posted
Comments
El_Codero 21-Apr-12 4:23am    
hm, tried your code and it works well, without exception. Generic exception is generally thrown if file couldn't be saved, you already have tried another filepath/permission?
djrocks0101 21-Apr-12 5:45am    
Yeah you are right..It was missing the permission to create file in that directory..
I just changed the drive to D:\ and it worked for me.

1 solution

It's a permissions problem: Win7 (and Vista IIRC) will not allow a general user write permission to the root folder of the system disk.
Move your image file to a subdirectory that you can write in, and you will be fine:
C#
bitmap.Save("C:\\Temp\\test.jpg",ImageFormat.Jpeg);
 
Share this answer
 
Comments
djrocks0101 21-Apr-12 5:35am    
Thanks OG.
OriginalGriff 21-Apr-12 5:45am    
You're welcome

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900