| | |
PictureBox Image.Save Error
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2008
Posts: 52
Reputation:
Solved Threads: 6
Just for the heck of it I'm building a graphic editor, mainly to see how far I can take it and how much I can learn as I go. I'm having a problem with Image.Save.
First I have an MDI parent form from which graphic files can be opened. After selecting the file in an OPenDialog (ODialog) I create an instance of a form and load the picture into the Picturebox the form contains:
Later on when I need to use a color blotter type function I am converting the picturebox image into a stream and saving it to a bitmap so that I can use the GetPixel function to pull the color under the mouse. The strange thing is it only seems to work for PNG files. Every other type of file is giving me the "A first chance exception of type 'System.Runtime.InteropServices.ExternalException' occurred in System.Drawing.dll
A generic error occurred in GDI+." error message, which the documentation says means, "The image was saved with the wrong image format."
The code looks like this:
The Select Case does generate the correct ImageFormat. The error is generated on the
I guess I am looking for anyone who might have a clue as to the problem or knows another (better!, faster!) way of getting the color of a pixel out of a picturebox.
First I have an MDI parent form from which graphic files can be opened. After selecting the file in an OPenDialog (ODialog) I create an instance of a form and load the picture into the Picturebox the form contains:
VisualBasic Syntax (Toggle Plain Text)
frmPic = New frmPicture frmPic.Text = ODialog.SafeFileName frmPic.SavedFullName = ODialog.FileName frmPic.MdiParent = Me frmPic.PictureBox1.Load(ODialog.FileName) frmPic.Show()
Later on when I need to use a color blotter type function I am converting the picturebox image into a stream and saving it to a bitmap so that I can use the GetPixel function to pull the color under the mouse. The strange thing is it only seems to work for PNG files. Every other type of file is giving me the "A first chance exception of type 'System.Runtime.InteropServices.ExternalException' occurred in System.Drawing.dll
A generic error occurred in GDI+." error message, which the documentation says means, "The image was saved with the wrong image format."
The code looks like this:
VisualBasic Syntax (Toggle Plain Text)
Select Case Me.Text.Substring(Text.LastIndexOf(".") + 1).ToLower Case "bmp" TheFmt = ImageFormat.Bmp Case "gif" TheFmt = ImageFormat.Gif Case "jpg" TheFmt = ImageFormat.Jpeg Case "png" TheFmt = ImageFormat.Png Case "wmf" TheFmt = ImageFormat.Wmf End Select Try PictureBox1.Image.Save(TheStream, TheFmt) ThePicture = Bitmap.FromStream(TheStream) Catch ex As Exception Debug.Print(ex.Message) End Try
The Select Case does generate the correct ImageFormat. The error is generated on the
PictureBox1.Image.Save(TheStream, TheFmt) line, but like I said, works as advertised if I use a PNG file. I guess I am looking for anyone who might have a clue as to the problem or knows another (better!, faster!) way of getting the color of a pixel out of a picturebox.
•
•
Join Date: Feb 2008
Posts: 52
Reputation:
Solved Threads: 6
Well, I just tried to skip the conversion to a memorystream altogether and replaced
with
and it worked. This is what usually happens when I ask for help, I figure it out shortly thereafter.
VisualBasic Syntax (Toggle Plain Text)
PictureBox1.Image.Save(TheStream, TheFmt) ThePicture = Bitmap.FromStream(TheStream)
with
VisualBasic Syntax (Toggle Plain Text)
ThePicture = PictureBox1.Image
and it worked. This is what usually happens when I ask for help, I figure it out shortly thereafter.
![]() |
Similar Threads
- Generic error in GDI+ (C#)
- Multiple images to a single bmp/jpg image (Visual Basic 4 / 5 / 6)
- Please help me find problem in code :) (C#)
Other Threads in the VB.NET Forum
- Previous Thread: Can some1 give me maximum of validation on....
- Next Thread: SHA-256 in .NET
| Thread Tools | Search this Thread |
.net 30minutes 2005 2008 access account arithmetic array arrays basic binary bing button buttons c# center check checkbox code combobox component connectionstring convert crystalreport data database databasesearch datagrid datagridview design dissertation dissertations dissertationthesis dropdownlist excel file-dialog folder ftp generatetags google gridview hardcopy image images inline insert intel internet listview mobile monitor ms net networking output passingparameters peertopeervideostreaming picturebox picturebox1 plugin port print printing problem problemwithinstallation project reports" save searchbox searchvb.net select serial server soap sorting table tcp text textbox timer toolbox trim update updown user usercontrol vb vb.net vb.netcode vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet view visual visualbasic visualbasic.net visualstudio visualstudio2008 web wpf





