473,382 Members | 1,313 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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.InteropServices.ExternalException' 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.ExternalException:
A generic error occurred in GDI+.
at System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder,
EncoderParameters encoderParams)
at System.Drawing.Image.Save(Stream stream, ImageFormat format)
at _2DFunctionPlot.Form1.saveGraphicClick(Object sender, EventArgs
e) in c:\documents and settings\cdj.mobile-frege.000\stuff\c#
stuff\2dfunctionplot\form1.cs:line 1005
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventAr gs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage (Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG&
msg)
at System.Windows.Forms.ComponentManager.System.Windo ws.Forms.UnsafeNativeMethods+IMsoComponentManager. FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.ThreadContext.RunMessageLoopI nner(Int32
reason, ApplicationContext context)
at System.Windows.Forms.ThreadContext.RunMessageLoop( Int32 reason,
ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at _2DFunctionPlot.Form1.Main() in c:\documents and
settings\cdj.mobile-frege.000\stuff\c#
stuff\2dfunctionplot\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 saveGraphicClick(object sender, System.EventArgs e)
{
// Displays a SaveFileDialog so the user can save the Image
// assigned to Button2.
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "JPeg Image|*.jpg|Bitmap 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(saveFileDialog1.FileName != "")
{
// Saves the Image via a FileStream created by the OpenFile
method.
System.IO.FileStream fs =
(System.IO.FileStream)saveFileDialog1.OpenFile();
// 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(saveFileDialog1.FilterIndex)
{
case 1 :
this.graphicsBox.Image.Save(fs,
System.Drawing.Imaging.ImageFormat.Jpeg);
break;

case 2 :
this.graphicsBox.Image.Save(fs,
System.Drawing.Imaging.ImageFormat.Bmp);
break;

case 3 :
this.graphicsBox.Image.Save(fs,
System.Drawing.Imaging.ImageFormat.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 3575
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_******@hotmail.com> wrote in message
news:b0**************************@posting.google.c om...
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.InteropServices.ExternalException' 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.ExternalException:
A generic error occurred in GDI+.
at System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder,
EncoderParameters encoderParams)
at System.Drawing.Image.Save(Stream stream, ImageFormat format)
at _2DFunctionPlot.Form1.saveGraphicClick(Object sender, EventArgs
e) in c:\documents and settings\cdj.mobile-frege.000\stuff\c#
stuff\2dfunctionplot\form1.cs:line 1005
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventAr gs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage (Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG&
msg)
at System.Windows.Forms.ComponentManager.System.Windo ws.Forms.UnsafeNativeMetho
ds+IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.ThreadContext.RunMessageLoopI nner(Int32
reason, ApplicationContext context)
at System.Windows.Forms.ThreadContext.RunMessageLoop( Int32 reason,
ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at _2DFunctionPlot.Form1.Main() in c:\documents and
settings\cdj.mobile-frege.000\stuff\c#
stuff\2dfunctionplot\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 saveGraphicClick(object sender, System.EventArgs e)
{
// Displays a SaveFileDialog so the user can save the Image
// assigned to Button2.
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "JPeg Image|*.jpg|Bitmap 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(saveFileDialog1.FileName != "")
{
// Saves the Image via a FileStream created by the OpenFile
method.
System.IO.FileStream fs =
(System.IO.FileStream)saveFileDialog1.OpenFile();
// 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(saveFileDialog1.FilterIndex)
{
case 1 :
this.graphicsBox.Image.Save(fs,
System.Drawing.Imaging.ImageFormat.Jpeg);
break;

case 2 :
this.graphicsBox.Image.Save(fs,
System.Drawing.Imaging.ImageFormat.Bmp);
break;

case 3 :
this.graphicsBox.Image.Save(fs,
System.Drawing.Imaging.ImageFormat.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_******@hotmail.com> wrote in message
news:b0**************************@posting.google.c om...
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.InteropServices.ExternalException' 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.ExternalException:
A generic error occurred in GDI+.
at System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder,
EncoderParameters encoderParams)
at System.Drawing.Image.Save(Stream stream, ImageFormat format)
at _2DFunctionPlot.Form1.saveGraphicClick(Object sender, EventArgs
e) in c:\documents and settings\cdj.mobile-frege.000\stuff\c#
stuff\2dfunctionplot\form1.cs:line 1005
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventAr gs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage (Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG&
msg)
at System.Windows.Forms.ComponentManager.System.Windo ws.Forms.UnsafeNativeMetho
ds+IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.ThreadContext.RunMessageLoopI nner(Int32
reason, ApplicationContext context)
at System.Windows.Forms.ThreadContext.RunMessageLoop( Int32 reason,
ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at _2DFunctionPlot.Form1.Main() in c:\documents and
settings\cdj.mobile-frege.000\stuff\c#
stuff\2dfunctionplot\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 saveGraphicClick(object sender, System.EventArgs e)
{
// Displays a SaveFileDialog so the user can save the Image
// assigned to Button2.
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "JPeg Image|*.jpg|Bitmap 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(saveFileDialog1.FileName != "")
{
// Saves the Image via a FileStream created by the OpenFile
method.
System.IO.FileStream fs =
(System.IO.FileStream)saveFileDialog1.OpenFile();
// 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(saveFileDialog1.FilterIndex)
{
case 1 :
this.graphicsBox.Image.Save(fs,
System.Drawing.Imaging.ImageFormat.Jpeg);
break;

case 2 :
this.graphicsBox.Image.Save(fs,
System.Drawing.Imaging.ImageFormat.Bmp);
break;

case 3 :
this.graphicsBox.Image.Save(fs,
System.Drawing.Imaging.ImageFormat.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***********@SPAMsympaticoPLEASE.ca> wrote in message news:<en**************@TK2MSFTNGP10.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
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...
4
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,...
1
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...
8
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
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
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...
1
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...
4
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...
1
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.