473,408 Members | 2,888 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,408 software developers and data experts.

saving images fro mpicturebox..

hi again.. i wrote a simple "paint" program which u can paint a picture on a
picture box and then save it to a bmpof jpg file..
my problem is whenever i try to save the file program throws
"'System.NullReferenceException".

i save the picture like this:
"picturebox1.image.save("temp.bmp",imageformat.bmp )

and also drawing the pictuer on the picturebox like this:

Mousedown event:

if(e.Button == MouseButtons.Left)
{
Graphics g = pictureBox1.CreateGraphics();
g.DrawEllipse(new Pen(Color.Black,5),e.X,e.Y,5,5);
}

i tried everything i know (and also found in google) but it still throws the
same exception. plase help :(

p.s: thanx for answering my everlasting questions by spending your time..
p.s2: im using this newsteller from outlook express and i cant reply from
there.. do u know a way to do that? thanx for spending your time agian. have
a nice day.


Nov 16 '05 #1
2 1334
You are drawing on the canvas of the picturebox, but trying to save the
Image from the picturebox. That is the cause of the problem.

Instead of drawing straight to the canvas, try this:

In your form constructor,

pictureBox1.Image = new Bitmap(pictureBox1.Width, pictureBox1.Height);

In your event handler,

if (e.Button == MouseButtons.Left)
{
Graphics g = Graphics.FromImage(pictureBox1.Image);
g.DrawEllipse(new Pen(Color.Black, 5), e.X, e.Y, 5, 5);
g.Dispose();
}

And now, you can save the image,

pictureBox1.Image.Save(...);

-vJ

"Serdar C." <se*****@interaktif.gen.tr> wrote in message
news:uT**************@tk2msftngp13.phx.gbl...
hi again.. i wrote a simple "paint" program which u can paint a picture on
a
picture box and then save it to a bmpof jpg file..
my problem is whenever i try to save the file program throws
"'System.NullReferenceException".

i save the picture like this:
"picturebox1.image.save("temp.bmp",imageformat.bmp )

and also drawing the pictuer on the picturebox like this:

Mousedown event:

if(e.Button == MouseButtons.Left)
{
Graphics g = pictureBox1.CreateGraphics();
g.DrawEllipse(new Pen(Color.Black,5),e.X,e.Y,5,5);
}

i tried everything i know (and also found in google) but it still throws
the
same exception. plase help :(

p.s: thanx for answering my everlasting questions by spending your time..
p.s2: im using this newsteller from outlook express and i cant reply from
there.. do u know a way to do that? thanx for spending your time agian.
have
a nice day.

Nov 16 '05 #2
thanx for helping its working now :)
"Vijaye Raji" <no*************@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
You are drawing on the canvas of the picturebox, but trying to save the
Image from the picturebox. That is the cause of the problem.

Instead of drawing straight to the canvas, try this:

In your form constructor,

pictureBox1.Image = new Bitmap(pictureBox1.Width, pictureBox1.Height);

In your event handler,

if (e.Button == MouseButtons.Left)
{
Graphics g = Graphics.FromImage(pictureBox1.Image);
g.DrawEllipse(new Pen(Color.Black, 5), e.X, e.Y, 5, 5);
g.Dispose();
}

And now, you can save the image,

pictureBox1.Image.Save(...);

-vJ

"Serdar C." <se*****@interaktif.gen.tr> wrote in message
news:uT**************@tk2msftngp13.phx.gbl...
hi again.. i wrote a simple "paint" program which u can paint a picture on a
picture box and then save it to a bmpof jpg file..
my problem is whenever i try to save the file program throws
"'System.NullReferenceException".

i save the picture like this:
"picturebox1.image.save("temp.bmp",imageformat.bmp )

and also drawing the pictuer on the picturebox like this:

Mousedown event:

if(e.Button == MouseButtons.Left)
{
Graphics g = pictureBox1.CreateGraphics();
g.DrawEllipse(new Pen(Color.Black,5),e.X,e.Y,5,5);
}

i tried everything i know (and also found in google) but it still throws
the
same exception. plase help :(

p.s: thanx for answering my everlasting questions by spending your time.. p.s2: im using this newsteller from outlook express and i cant reply from there.. do u know a way to do that? thanx for spending your time agian.
have
a nice day.


Nov 16 '05 #3

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

Similar topics

1
by: Lovely Angel For You | last post by:
Dear Friends Hope you all doing great. I have this problem. When I try to save any ASP page, I get the message that "The page will not save correctly". Even though I go ahead and when I go...
1
by: M Keeton | last post by:
I currently have a picture which is stored in a "System.Drawing.Image" variable and I want to save it as a bitmap file. I have tried 2 different approaches and both give me the following error: ...
16
by: Fred | last post by:
hi, is there some way to prevent(at least for not so advanced users) image saving on local disk; currently i use javascript which handles the right mouse button click, but all it takes is to...
6
by: NutsAboutVB | last post by:
Hello, I am a .NET programmer and I have a JPEG image file (from digital camera) of about 109 KB's in size, when I open it and save it (without making any alterations at all, just going to File...
6
by: Eddie | last post by:
Hi all, I am displaying a number of reports, and giving the users an option to display them on the web or download them to Excel. If they want the Excel file, I just use the PHP header command...
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: 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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.