473,387 Members | 1,790 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,387 software developers and data experts.

PictureBox to a file

Hello coders:

How do I save the image painted on a Graphics object into a file?

I get an exception when I try to do:

Image.FromHbitmap(
pictureBox.CreateGraphics().GetHdc()
).Save("C:\location\file.jpg")

The exception is:

An unhandled exception of type
'System.Runtime.InteropServices.ExternalException' occurred in
system.drawing.dll

Additional information: A generic error occurred in GDI+.

I'm sure it must be an easy way to save the changes made on a PictureBox.

Thank you. Samuel.
Nov 15 '05 #1
1 6061

Samuel <sa********@msn.com> wrote in message
news:Ot**************@tk2msftngp13.phx.gbl...
Hello coders:

How do I save the image painted on a Graphics object into a file?

I get an exception when I try to do:

Image.FromHbitmap(
pictureBox.CreateGraphics().GetHdc()
).Save("C:\location\file.jpg")

The exception is:

An unhandled exception of type
'System.Runtime.InteropServices.ExternalException' occurred in
system.drawing.dll

Additional information: A generic error occurred in GDI+.

I'm sure it must be an easy way to save the changes made on a PictureBox.

Thank you. Samuel.

That is described by Erik Brown's book "Windows Forms with C#". You can
download the example code from the Manning website www.manning.com.

Patrick.


Nov 15 '05 #2

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

Similar topics

8
by: Pavan Arise | last post by:
Dear all.. I have a picturebox filled on a form. The picturebox has some graphics displayed on it.I was trying to save the picturebox, but continuesly failed to do so. I am clueless of why it is...
12
by: yaya via DotNetMonster.com | last post by:
Hi, I have a picture box with circles and rectangles, and I wana save all the images into a jpg file, i tried pictureBox1.Image.Save(@"c:\1.jpg"); but I got and error...
2
by: Sharon | last post by:
I encountered a strange behavior when doing ‘new Bitmap’: The following code works fine and the given bitmap file is shown on the PictureBox (the m_DrawArea) in the correct bitmap sizes: ...
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 --------------------------------------
2
by: Mattbooty | last post by:
Hello, Not sure if anyone else has seen this bug, but I have a form where the entire form is covered with a picturebox. The picturebox has a mouseup event. I also have an open file dialog for...
4
by: TomA | last post by:
Hi All, I have a picturebox on a form containing the photo of a person. As you advance through the records, the photo updates. Rather than storing the images in an inefficient blob field in a...
3
by: kirk | last post by:
I have a form with a PictureBox control on it. The .Image property is set to a PNG file(which shows the picture of the US map) with some transparency in it. The .BackColor property is set to...
1
by: Nitin | last post by:
Hi! I've been trying to draw in a PictureBox and save the resulting image to a Bitmap object that I save to a file on disk. Unfortunately, I can't seem to get the elements that I'm drawing to...
4
by: gerardianlewis | last post by:
Any help appreciated. (VB.NET under XP and Vista, SP1 installed) My code, inherited from a VB6 version of an app that ran under W98, loads an image from a file into a PictureBox. The user may...
1
by: leshka82 | last post by:
I have recently designed a Winform Image drag & drop utility. The approach I took was to have a Panel control serve as a destination for multiple file drop. Once the user dragged & dropped the...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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:
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...
0
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,...

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.