473,729 Members | 2,150 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

trouble saving a jpg out of a picturebox....

cdj
Hi all,

I've got a picturebox on a form, and a save button. When I go to save,
the app craps out with the following error:

=============== ===
An unhandled exception of type
'System.Runtime .InteropService s.ExternalExcep tion' occurred in
system.drawing. dll

Additional information: A generic error occurred in GDI+.
=============== ===
And here's the additional GDI+ error info:

=============== ===
Unhandled Exception: System.Runtime. InteropServices .ExternalExcept ion:
A generic error occurred in GDI+.
at System.Drawing. Image.Save(Stre am stream, ImageCodecInfo encoder,
EncoderParamete rs encoderParams)
at System.Drawing. Image.Save(Stre am stream, ImageFormat format)
at _2DFunctionPlot .Form1.saveGrap hicClick(Object sender, EventArgs
e) in c:\documents and settings\cdj.mo bile-frege.000\stuff \c#
stuff\2dfunctio nplot\form1.cs: line 1005
at System.Windows. Forms.Control.O nClick(EventArg s e)
at System.Windows. Forms.Button.On Click(EventArgs e)
at System.Windows. Forms.Button.On MouseUp(MouseEv entArgs mevent)
at System.Windows. Forms.Control.W mMouseUp(Messag e& m, MouseButtons
button, Int32 clicks)
at System.Windows. Forms.Control.W ndProc(Message& m)
at System.Windows. Forms.ButtonBas e.WndProc(Messa ge& m)
at System.Windows. Forms.Button.Wn dProc(Message& m)
at System.Windows. Forms.ControlNa tiveWindow.OnMe ssage(Message& m)
at System.Windows. Forms.ControlNa tiveWindow.WndP roc(Message& m)
at System.Windows. Forms.NativeWin dow.DebuggableC allback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows. Forms.UnsafeNat iveMethods.Disp atchMessageW(MS G&
msg)
at System.Windows. Forms.Component Manager.System. Windows.Forms.U nsafeNativeMeth ods+IMsoCompone ntManager.FPush MessageLoop(Int 32
dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows. Forms.ThreadCon text.RunMessage LoopInner(Int32
reason, ApplicationCont ext context)
at System.Windows. Forms.ThreadCon text.RunMessage Loop(Int32 reason,
ApplicationCont ext context)
at System.Windows. Forms.Applicati on.Run(Form mainForm)
at _2DFunctionPlot .Form1.Main() in c:\documents and
settings\cdj.mo bile-frege.000\stuff \c#
stuff\2dfunctio nplot\form1.cs: line 663The program '[5460]
2DFunctionPlot. exe' has exited with code 0 (0x0).
===============

I'm new to .net programming - this lil app is meant to be a learning
experience, in fact. Here's the code for my save routing, which is
"simply" a trivial variant of what's on MSDN:

=============== ============
private void saveGraphicClic k(object sender, System.EventArg s e)
{
// Displays a SaveFileDialog so the user can save the Image
// assigned to Button2.
SaveFileDialog saveFileDialog1 = new SaveFileDialog( );
saveFileDialog1 .Filter = "JPeg Image|*.jpg|Bit map Image|*.bmp|Gif
Image|*.gif";
saveFileDialog1 .Title = "Save an Image File";
saveFileDialog1 .ShowDialog();

// If the file name is not an empty string open it for saving.
if(saveFileDial og1.FileName != "")
{
// Saves the Image via a FileStream created by the OpenFile
method.
System.IO.FileS tream fs =
(System.IO.File Stream)saveFile Dialog1.OpenFil e();
// Saves the Image in the appropriate ImageFormat based upon the
// File type selected in the dialog box.
// NOTE that the FilterIndex property is one-based.
switch(saveFile Dialog1.FilterI ndex)
{
case 1 :
this.graphicsBo x.Image.Save(fs ,
System.Drawing. Imaging.ImageFo rmat.Jpeg);
break;

case 2 :
this.graphicsBo x.Image.Save(fs ,
System.Drawing. Imaging.ImageFo rmat.Bmp);
break;

case 3 :
this.graphicsBo x.Image.Save(fs ,
System.Drawing. Imaging.ImageFo rmat.Gif);
break;
}

fs.Close();
}
}
=============

The graphic I'm trying to save is always a jpg, and thus the error
always occurs in the Case1 save statement.

Does anyone know what I'm doing wrong?

(please let me know if I haven't supplied enuff/relevant info, i'll be
glad to provide it...)

thx for any insights,

cdj
Nov 16 '05 #1
3 3623
Can you do image.Load for same jpeg w/o error? Are you creating image
yourself or using precereated one?

I've seen cases when jpeg engine in .Net was unable to display image, which
IE or PhotoEditor were able to show just fine. With similar internal GDI
errors. I think this issue exists since Beta.

You might try to find some special way to save such problematic images. E.g.
like bitmaps, which you convert later using some other tools.

HTH
Alex

"cdj" <a_******@hotma il.com> wrote in message
news:b0******** *************** ***@posting.goo gle.com...
Hi all,

I've got a picturebox on a form, and a save button. When I go to save,
the app craps out with the following error:

=============== ===
An unhandled exception of type
'System.Runtime .InteropService s.ExternalExcep tion' occurred in
system.drawing. dll

Additional information: A generic error occurred in GDI+.
=============== ===
And here's the additional GDI+ error info:

=============== ===
Unhandled Exception: System.Runtime. InteropServices .ExternalExcept ion:
A generic error occurred in GDI+.
at System.Drawing. Image.Save(Stre am stream, ImageCodecInfo encoder,
EncoderParamete rs encoderParams)
at System.Drawing. Image.Save(Stre am stream, ImageFormat format)
at _2DFunctionPlot .Form1.saveGrap hicClick(Object sender, EventArgs
e) in c:\documents and settings\cdj.mo bile-frege.000\stuff \c#
stuff\2dfunctio nplot\form1.cs: line 1005
at System.Windows. Forms.Control.O nClick(EventArg s e)
at System.Windows. Forms.Button.On Click(EventArgs e)
at System.Windows. Forms.Button.On MouseUp(MouseEv entArgs mevent)
at System.Windows. Forms.Control.W mMouseUp(Messag e& m, MouseButtons
button, Int32 clicks)
at System.Windows. Forms.Control.W ndProc(Message& m)
at System.Windows. Forms.ButtonBas e.WndProc(Messa ge& m)
at System.Windows. Forms.Button.Wn dProc(Message& m)
at System.Windows. Forms.ControlNa tiveWindow.OnMe ssage(Message& m)
at System.Windows. Forms.ControlNa tiveWindow.WndP roc(Message& m)
at System.Windows. Forms.NativeWin dow.DebuggableC allback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows. Forms.UnsafeNat iveMethods.Disp atchMessageW(MS G&
msg)
at System.Windows. Forms.Component Manager.System. Windows.Forms.U nsafeNativeMeth o
ds+IMsoComponen tManager.FPushM essageLoop(Int3 2 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows. Forms.ThreadCon text.RunMessage LoopInner(Int32
reason, ApplicationCont ext context)
at System.Windows. Forms.ThreadCon text.RunMessage Loop(Int32 reason,
ApplicationCont ext context)
at System.Windows. Forms.Applicati on.Run(Form mainForm)
at _2DFunctionPlot .Form1.Main() in c:\documents and
settings\cdj.mo bile-frege.000\stuff \c#
stuff\2dfunctio nplot\form1.cs: line 663The program '[5460]
2DFunctionPlot. exe' has exited with code 0 (0x0).
===============

I'm new to .net programming - this lil app is meant to be a learning
experience, in fact. Here's the code for my save routing, which is
"simply" a trivial variant of what's on MSDN:

=============== ============
private void saveGraphicClic k(object sender, System.EventArg s e)
{
// Displays a SaveFileDialog so the user can save the Image
// assigned to Button2.
SaveFileDialog saveFileDialog1 = new SaveFileDialog( );
saveFileDialog1 .Filter = "JPeg Image|*.jpg|Bit map Image|*.bmp|Gif
Image|*.gif";
saveFileDialog1 .Title = "Save an Image File";
saveFileDialog1 .ShowDialog();

// If the file name is not an empty string open it for saving.
if(saveFileDial og1.FileName != "")
{
// Saves the Image via a FileStream created by the OpenFile
method.
System.IO.FileS tream fs =
(System.IO.File Stream)saveFile Dialog1.OpenFil e();
// Saves the Image in the appropriate ImageFormat based upon the
// File type selected in the dialog box.
// NOTE that the FilterIndex property is one-based.
switch(saveFile Dialog1.FilterI ndex)
{
case 1 :
this.graphicsBo x.Image.Save(fs ,
System.Drawing. Imaging.ImageFo rmat.Jpeg);
break;

case 2 :
this.graphicsBo x.Image.Save(fs ,
System.Drawing. Imaging.ImageFo rmat.Bmp);
break;

case 3 :
this.graphicsBo x.Image.Save(fs ,
System.Drawing. Imaging.ImageFo rmat.Gif);
break;
}

fs.Close();
}
}
=============

The graphic I'm trying to save is always a jpg, and thus the error
always occurs in the Case1 save statement.

Does anyone know what I'm doing wrong?

(please let me know if I haven't supplied enuff/relevant info, i'll be
glad to provide it...)

thx for any insights,

cdj

Nov 16 '05 #2
Can you do image.Load for same jpeg w/o error? Are you creating image
yourself or using precereated one?

I've seen cases when jpeg engine in .Net was unable to display image, which
IE or PhotoEditor were able to show just fine. With similar internal GDI
errors. I think this issue exists since Beta.

You might try to find some special way to save such problematic images. E.g.
like bitmaps, which you convert later using some other tools.

HTH
Alex

"cdj" <a_******@hotma il.com> wrote in message
news:b0******** *************** ***@posting.goo gle.com...
Hi all,

I've got a picturebox on a form, and a save button. When I go to save,
the app craps out with the following error:

=============== ===
An unhandled exception of type
'System.Runtime .InteropService s.ExternalExcep tion' occurred in
system.drawing. dll

Additional information: A generic error occurred in GDI+.
=============== ===
And here's the additional GDI+ error info:

=============== ===
Unhandled Exception: System.Runtime. InteropServices .ExternalExcept ion:
A generic error occurred in GDI+.
at System.Drawing. Image.Save(Stre am stream, ImageCodecInfo encoder,
EncoderParamete rs encoderParams)
at System.Drawing. Image.Save(Stre am stream, ImageFormat format)
at _2DFunctionPlot .Form1.saveGrap hicClick(Object sender, EventArgs
e) in c:\documents and settings\cdj.mo bile-frege.000\stuff \c#
stuff\2dfunctio nplot\form1.cs: line 1005
at System.Windows. Forms.Control.O nClick(EventArg s e)
at System.Windows. Forms.Button.On Click(EventArgs e)
at System.Windows. Forms.Button.On MouseUp(MouseEv entArgs mevent)
at System.Windows. Forms.Control.W mMouseUp(Messag e& m, MouseButtons
button, Int32 clicks)
at System.Windows. Forms.Control.W ndProc(Message& m)
at System.Windows. Forms.ButtonBas e.WndProc(Messa ge& m)
at System.Windows. Forms.Button.Wn dProc(Message& m)
at System.Windows. Forms.ControlNa tiveWindow.OnMe ssage(Message& m)
at System.Windows. Forms.ControlNa tiveWindow.WndP roc(Message& m)
at System.Windows. Forms.NativeWin dow.DebuggableC allback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows. Forms.UnsafeNat iveMethods.Disp atchMessageW(MS G&
msg)
at System.Windows. Forms.Component Manager.System. Windows.Forms.U nsafeNativeMeth o
ds+IMsoComponen tManager.FPushM essageLoop(Int3 2 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows. Forms.ThreadCon text.RunMessage LoopInner(Int32
reason, ApplicationCont ext context)
at System.Windows. Forms.ThreadCon text.RunMessage Loop(Int32 reason,
ApplicationCont ext context)
at System.Windows. Forms.Applicati on.Run(Form mainForm)
at _2DFunctionPlot .Form1.Main() in c:\documents and
settings\cdj.mo bile-frege.000\stuff \c#
stuff\2dfunctio nplot\form1.cs: line 663The program '[5460]
2DFunctionPlot. exe' has exited with code 0 (0x0).
===============

I'm new to .net programming - this lil app is meant to be a learning
experience, in fact. Here's the code for my save routing, which is
"simply" a trivial variant of what's on MSDN:

=============== ============
private void saveGraphicClic k(object sender, System.EventArg s e)
{
// Displays a SaveFileDialog so the user can save the Image
// assigned to Button2.
SaveFileDialog saveFileDialog1 = new SaveFileDialog( );
saveFileDialog1 .Filter = "JPeg Image|*.jpg|Bit map Image|*.bmp|Gif
Image|*.gif";
saveFileDialog1 .Title = "Save an Image File";
saveFileDialog1 .ShowDialog();

// If the file name is not an empty string open it for saving.
if(saveFileDial og1.FileName != "")
{
// Saves the Image via a FileStream created by the OpenFile
method.
System.IO.FileS tream fs =
(System.IO.File Stream)saveFile Dialog1.OpenFil e();
// Saves the Image in the appropriate ImageFormat based upon the
// File type selected in the dialog box.
// NOTE that the FilterIndex property is one-based.
switch(saveFile Dialog1.FilterI ndex)
{
case 1 :
this.graphicsBo x.Image.Save(fs ,
System.Drawing. Imaging.ImageFo rmat.Jpeg);
break;

case 2 :
this.graphicsBo x.Image.Save(fs ,
System.Drawing. Imaging.ImageFo rmat.Bmp);
break;

case 3 :
this.graphicsBo x.Image.Save(fs ,
System.Drawing. Imaging.ImageFo rmat.Gif);
break;
}

fs.Close();
}
}
=============

The graphic I'm trying to save is always a jpg, and thus the error
always occurs in the Case1 save statement.

Does anyone know what I'm doing wrong?

(please let me know if I haven't supplied enuff/relevant info, i'll be
glad to provide it...)

thx for any insights,

cdj

Nov 16 '05 #3
cdj
"AlexS" <sa***********@ SPAMsympaticoPL EASE.ca> wrote in message news:<en******* *******@TK2MSFT NGP10.phx.gbl>. ..
Can you do image.Load for same jpeg w/o error? Are you creating image
yourself or using precereated one?
Hm. Never trid to do an image.load..... that's because the image is
being generated by another program (Mathematica), and being fed into
the picturebox. The image displays perfectly in the picturebox
everytime without fail.
You might try to find some special way to save such problematic images. E.g.
like bitmaps, which you convert later using some other tools.
o - so it might just be a problem with jps? i'll give gif and bmp a
try i guess.... i just figured i was making some kinda stupid coding
mistake.....
HTH
Alex


we'll see.... but i really appreciate your taking the time to
answer...

cdj
Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2273
by: Kate | last post by:
Hi: I have a picturebox control, and at runtime various usercontrols are added to it to make a diagram. As dynamically added usercontrols, they are of type VBExtender. Is there a way to save the diagram as a .wmf file? (The diagram might extend beyond the confines of the actual picturebox on the screen.) I have seen examples of how to print all the controls in a picturebox
4
7513
by: Carl | last post by:
In the application I'm writing, I'm modifying a windows bitmap using the circle and line methods. Once the changes have been made, I would like to save the bitmap with the changes. My problem is, after saving the bitmap I find that the changes haven't been saved with the new file. Any help with what I'm doing wrong? -Carl
1
6899
by: Dev | last post by:
Dear Friends, I am passing the image name, size (in bytes) and imgaeformat (like jpg or bmp or pdf) through the network. I want display the image into picturebox without saving image files into Hard disk. Just display the image into PictureBox.... Is it Possible? If so how do to this?
8
10782
by: nobody | last post by:
How do I save a PictureBox bitmap with changes drawn on the bitmap? This doesn't do it: PictureBox1.Image.Save("key30.bmp")
2
1235
by: Daniel | last post by:
Hi all, Is it possible to output the contents of a panel as a graphic file? -- Daniel MCSE, MCP+I, MCP in Windows 2000/NT --------------------------------------
5
2538
by: Steve Marshall | last post by:
Hi all, I am converting an app which used a picturebox to draw graphs etc onto, then saved them to a file. I can certainly draw things onto a picturbox in VB.NET, but how do I save them to a file? I've looked at Bitmap objects, which support saving, but can't see a way to grab what I have drawn and make a bitmap from it, or whatever. Anybody done this? Thanks for any suggestions
1
5440
by: Martin Horn | last post by:
Hi all, I'm trying to save a picturebox image to a database. This is part of the code I'm using:- <snip> Private drv As DataRowView Private dr As MainDataSet.OrdersRow If PictureBox.Image IsNot Nothing Then
4
1571
by: Lunchtimemama | last post by:
I have a UI with a gallery of thumbnail image previews. The PictureBoxes are created and their Images are generated by a method which quickly retrieves the icon for the filetype. Worker threads then asynchronously retrieve and resize the full image previews and update the PictureBox's Images when the new images are ready. The way I have it set up now, the method which generates the filetype icons creates and starts the new worker Threads....
1
11604
Sl1ver
by: Sl1ver | last post by:
i've got this piece of coding. i need help with opening a picture box and then saving it as OLE Object in access DB How would i massage this code tho fit in? try { //save image to byte array and allocate enough memory for the image byte imagedata = image.ToByteArray(new Atalasoft.Imaging.Codec.JpegEncoder(75));
0
8761
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9426
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9280
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9200
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6016
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2162
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.