GDI+ Error
-
Hi all. I am trying to save an image which i am creating in code. Everytime i call the Bitmap.Save Function i get an error "A generic problem occurred in GDI+". I have googled this for the past hour and have been unsuccessful. Her is the source code you need to understand what i am doing.
Dim bmp As New Bitmap(80, 80) Dim g As Graphics = Graphics.FromImage(bmp) Dim LinesPen As New Pen(Color.Black, 2) LinesPen.Alignment = Drawing2D.PenAlignment.Center g.DrawRectangle(LinesPen, 1, 1, 78, 78) g.DrawLine(LinesPen, 27, 1, 27, 79) g.DrawLine(LinesPen, 53, 1, 53, 79) g.DrawLine(LinesPen, 1, 27, 79, 27) g.DrawLine(LinesPen, 1, 53, 79, 53) Try '----------------ERROR HERE------------------ bmp.Save(Me.DestinationLabel.Text, System.Drawing.Imaging.ImageFormat.Png) '-------^^^^-----ERROR HERE-------^^^^------- Catch ex As Exception MessageBox.Show(ex.Message) End Try
Please help if you can or if you have also experienced this.Please check out my articles: The ANZAC's articles
-
Hi all. I am trying to save an image which i am creating in code. Everytime i call the Bitmap.Save Function i get an error "A generic problem occurred in GDI+". I have googled this for the past hour and have been unsuccessful. Her is the source code you need to understand what i am doing.
Dim bmp As New Bitmap(80, 80) Dim g As Graphics = Graphics.FromImage(bmp) Dim LinesPen As New Pen(Color.Black, 2) LinesPen.Alignment = Drawing2D.PenAlignment.Center g.DrawRectangle(LinesPen, 1, 1, 78, 78) g.DrawLine(LinesPen, 27, 1, 27, 79) g.DrawLine(LinesPen, 53, 1, 53, 79) g.DrawLine(LinesPen, 1, 27, 79, 27) g.DrawLine(LinesPen, 1, 53, 79, 53) Try '----------------ERROR HERE------------------ bmp.Save(Me.DestinationLabel.Text, System.Drawing.Imaging.ImageFormat.Png) '-------^^^^-----ERROR HERE-------^^^^------- Catch ex As Exception MessageBox.Show(ex.Message) End Try
Please help if you can or if you have also experienced this.Please check out my articles: The ANZAC's articles
Hi, Most, if not all, errors inside GDI+ are reported as "generic problem occurred in GDI+". If the affected line is an Image.Save chances are your path is incorrect or inaccessible, your disk is full, or your destination file exists and is locked. if you load an image from a file, most of the time the file remains locked as long as the Image is alive. This would prevent you from saving an image to the same path. It applies to Image.FromFile, and probably also to PictureBox.ImageLocation The one exception I am aware of is when you use Image.FromStream An alternative work-around is to work with a copy of the image: load the image with Image.FromFile, create a new image from it with new Bitmap(Image), dispose of the original image. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Sorry for any delays in replying, I currently don't get e-mail notifications.
-
Hi all. I am trying to save an image which i am creating in code. Everytime i call the Bitmap.Save Function i get an error "A generic problem occurred in GDI+". I have googled this for the past hour and have been unsuccessful. Her is the source code you need to understand what i am doing.
Dim bmp As New Bitmap(80, 80) Dim g As Graphics = Graphics.FromImage(bmp) Dim LinesPen As New Pen(Color.Black, 2) LinesPen.Alignment = Drawing2D.PenAlignment.Center g.DrawRectangle(LinesPen, 1, 1, 78, 78) g.DrawLine(LinesPen, 27, 1, 27, 79) g.DrawLine(LinesPen, 53, 1, 53, 79) g.DrawLine(LinesPen, 1, 27, 79, 27) g.DrawLine(LinesPen, 1, 53, 79, 53) Try '----------------ERROR HERE------------------ bmp.Save(Me.DestinationLabel.Text, System.Drawing.Imaging.ImageFormat.Png) '-------^^^^-----ERROR HERE-------^^^^------- Catch ex As Exception MessageBox.Show(ex.Message) End Try
Please help if you can or if you have also experienced this.Please check out my articles: The ANZAC's articles
If you load the image using FromFile, the file is locked for the entire liftime of the image object. This means you cannot save it back to the original file because of the lock. Instead, use the FromStream method to load the image. When you close your FileStream object, the lock is released, then you can save the image back to the original file.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
If you load the image using FromFile, the file is locked for the entire liftime of the image object. This means you cannot save it back to the original file because of the lock. Instead, use the FromStream method to load the image. When you close your FileStream object, the lock is released, then you can save the image back to the original file.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007You're obviously right, but I recently found a case where if I used a stream, and then draw the image onto a new bitmap, it was drawn at 1/4 size. I don't know why this was happening, but it was a repeatable bug across many ( users ) machines.
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
You're obviously right, but I recently found a case where if I used a stream, and then draw the image onto a new bitmap, it was drawn at 1/4 size. I don't know why this was happening, but it was a repeatable bug across many ( users ) machines.
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
Christian Graus wrote:
if I used a stream, and then draw the image onto a new bitmap, it was drawn at 1/4 size. I don't know why this was happening, but it was a repeatable bug across many ( users ) machines.
That's whacked. I haven't seen it happen myself, ...yet. Hmmm. Any clues on the image format that it was using? TIFF, BMP, JPEG, all of the above? Dimensions, color depth, pixel format, compression?
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
Christian Graus wrote:
if I used a stream, and then draw the image onto a new bitmap, it was drawn at 1/4 size. I don't know why this was happening, but it was a repeatable bug across many ( users ) machines.
That's whacked. I haven't seen it happen myself, ...yet. Hmmm. Any clues on the image format that it was using? TIFF, BMP, JPEG, all of the above? Dimensions, color depth, pixel format, compression?
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007They were JPEGs, they were a fair size, and they were 24 bit.
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
Hi, Most, if not all, errors inside GDI+ are reported as "generic problem occurred in GDI+". If the affected line is an Image.Save chances are your path is incorrect or inaccessible, your disk is full, or your destination file exists and is locked. if you load an image from a file, most of the time the file remains locked as long as the Image is alive. This would prevent you from saving an image to the same path. It applies to Image.FromFile, and probably also to PictureBox.ImageLocation The one exception I am aware of is when you use Image.FromStream An alternative work-around is to work with a copy of the image: load the image with Image.FromFile, create a new image from it with new Bitmap(Image), dispose of the original image. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Sorry for any delays in replying, I currently don't get e-mail notifications.
I am not using FromFile. The image does not exist and is not overwriting another image. It is a completely new image which i have drawn the graphics from then added graphics objects (rectangles and lines) to, i still recive the same error. I just can't save it for some reason. I have no idea why. I have tried making a second image of the same size and making it equal the first one then saving the second one and i still have problems.
Please check out my articles: The ANZAC's articles
-
I am not using FromFile. The image does not exist and is not overwriting another image. It is a completely new image which i have drawn the graphics from then added graphics objects (rectangles and lines) to, i still recive the same error. I just can't save it for some reason. I have no idea why. I have tried making a second image of the same size and making it equal the first one then saving the second one and i still have problems.
Please check out my articles: The ANZAC's articles
OK, some questions then: 1. is your path correct? 2. do all the (sub)directories exist? 3. is the path refering to an existing file? 4. if so, did that file get created very recently? explain! :)
Luc Pattyn [Forum Guidelines] [My Articles]
Sorry for any delays in replying, I currently don't always get e-mail notifications.
-
OK, some questions then: 1. is your path correct? 2. do all the (sub)directories exist? 3. is the path refering to an existing file? 4. if so, did that file get created very recently? explain! :)
Luc Pattyn [Forum Guidelines] [My Articles]
Sorry for any delays in replying, I currently don't always get e-mail notifications.
Problem Solved, there was a slight error in the way i dealt with the filename.
Please check out my articles: The ANZAC's articles