473,573 Members | 2,910 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 3594
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
2267
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...
4
7507
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
6891
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
10774
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
1221
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
2515
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. ...
1
5431
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
1563
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...
1
11588
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
8021
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. ...
0
8202
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...
0
6419
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5291
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...
0
3732
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...
0
3733
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2213
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1303
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1041
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...

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.