Click here to Skip to main content
15,670,482 members
Home / Discussions / C#
   

C#

 
GeneralRe: Giving an object multiple enumerator types Pin
Christian Graus30-Jun-07 16:26
protectorChristian Graus30-Jun-07 16:26 
GeneralRe: Giving an object multiple enumerator types Pin
Rareed30-Jun-07 16:32
Rareed30-Jun-07 16:32 
GeneralRe: Giving an object multiple enumerator types Pin
Robert Rohde1-Jul-07 2:56
Robert Rohde1-Jul-07 2:56 
QuestionSave data into a .dat file Pin
atlasliu30-Jun-07 14:44
atlasliu30-Jun-07 14:44 
AnswerRe: Save data into a .dat file Pin
Luc Pattyn30-Jun-07 14:59
sitebuilderLuc Pattyn30-Jun-07 14:59 
QuestionImage Processing using C# Pin
marwa wael30-Jun-07 7:04
marwa wael30-Jun-07 7:04 
AnswerRe: Image Processing using C# Pin
zeeShan anSari30-Jun-07 9:01
zeeShan anSari30-Jun-07 9:01 
QuestionImageprocessing:Draw and Save the drawing Pin
zeeShan anSari30-Jun-07 6:34
zeeShan anSari30-Jun-07 6:34 
Hi,
By your help I able to draw the any shape into the pictureBox and able to save the drawing.
It is a simple way to save any image from the pictureBox
pictureBox2.Image.Save(saveFileDialog1.FileName);
but above command do work when any image is already load onto the pictureBox.otherwise some error occur like that:
"NullReferenceExpection was unhandled !"<br />
 "Object reference not set to an instance of an object."



“this is because you can't actually draw inside a picturebox. Although it may look like you're doing so, you are in fact drawing 'on top of' the picturebox and the image is not changed. So, if you haven't loaded an image, then the Image property will still be null.”


“If you use a picturebox, put a picture in it, and draw on it first. Then you can save it. CreateGraphics should be used only for drawing things you want to be able to erase, such as rubber bands. It is not for persistent drawing, and certainly it makes your picture box a waste of time, it never does anything”
Solution of above problem is that

“You need to make the graphics drawn on the PictureBox to be a persistent bitmap then only you can save the image.
Use a bitmap to draw the images upon and then reflect it upon your pictureboc. When you want to save just save the bitmap.”

So, I use follwing command to draw any thing

Bitmap bmp = new Bitmap(pictureBox.Width, pictureBox.Height);<br />
Graphics g1 = Graphics.FromImage(bmp);<br />
Graphics  g2 = pictureBox.CreateGraphics();<br />
Pen p = new Pen(Color.Red, 5);<br />
g1.DrawEllipse(p, e.X, e.Y, 50, 70);<br />
g2.DrawEllipse(p, e.X, e.Y, 50, 70); //etc…


And use follwing command for save the drawing

if (saveFileDialog1.ShowDialog() == DialogResult.OK)<br />
            {<br />
               <br />
                bmp.Save(saveFileDialog1.FileName);<br />
                <br />
            }


Am I success???
You notice that I use both bitmap and pictureBox at a time
Bitmap bmp = new Bitmap(pictureBox.Width, pictureBox.Height);<br />
Graphics g1 = Graphics.FromImage(bmp);<br />
Graphics  g2 = pictureBox.CreateGraphics();<br />
g1.DrawEllipse(p, e.X, e.Y, 50, 70);<br />
g2.DrawEllipse(p, e.X, e.Y, 50, 70);


I used bitmap for save(hard copy) the drawing and pictureBox used for seeing(soft copy) the image from the screen ………Am I right?

Many Thanks
AnswerRe: Imageprocessing:Draw and Save the drawing Pin
Guffa30-Jun-07 6:49
Guffa30-Jun-07 6:49 
AnswerRe: Imageprocessing:Draw and Save the drawing Pin
zeeShan anSari30-Jun-07 8:54
zeeShan anSari30-Jun-07 8:54 
GeneralRe: Imageprocessing:Draw and Save the drawing Pin
Christian Graus30-Jun-07 10:39
protectorChristian Graus30-Jun-07 10:39 
AnswerRe: Imageprocessing:Draw and Save the drawing Pin
Guffa30-Jun-07 11:34
Guffa30-Jun-07 11:34 
AnswerRe: Imageprocessing:Draw and Save the drawing Pin
Christian Graus30-Jun-07 10:30
protectorChristian Graus30-Jun-07 10:30 
Questionhow to access database Pin
nidesh30-Jun-07 5:07
nidesh30-Jun-07 5:07 
AnswerRe: how to access database Pin
WillemM30-Jun-07 6:58
WillemM30-Jun-07 6:58 
AnswerRe: how to access database Pin
Paul Conrad30-Jun-07 7:10
professionalPaul Conrad30-Jun-07 7:10 
GeneralRe: how to access database Pin
Expert Coming30-Jun-07 11:06
Expert Coming30-Jun-07 11:06 
GeneralRe: how to access database Pin
Paul Conrad30-Jun-07 14:02
professionalPaul Conrad30-Jun-07 14:02 
QuestionHelp with TypeLoadException (marshaling unmanaged code) Pin
TomWolfstein30-Jun-07 4:50
TomWolfstein30-Jun-07 4:50 
AnswerRe: Help with TypeLoadException (marshaling unmanaged code) Pin
Luc Pattyn30-Jun-07 5:10
sitebuilderLuc Pattyn30-Jun-07 5:10 
GeneralRe: Help with TypeLoadException (marshaling unmanaged code) Pin
TomWolfstein30-Jun-07 6:05
TomWolfstein30-Jun-07 6:05 
GeneralRe: Help with TypeLoadException (marshaling unmanaged code) Pin
Luc Pattyn30-Jun-07 6:57
sitebuilderLuc Pattyn30-Jun-07 6:57 
GeneralRe: Help with TypeLoadException (marshaling unmanaged code) Pin
TomWolfstein30-Jun-07 8:51
TomWolfstein30-Jun-07 8:51 
GeneralRe: Help with TypeLoadException (marshaling unmanaged code) Pin
Luc Pattyn30-Jun-07 14:27
sitebuilderLuc Pattyn30-Jun-07 14:27 
GeneralRe: Help with TypeLoadException (marshaling unmanaged code) Pin
TomWolfstein1-Jul-07 7:16
TomWolfstein1-Jul-07 7:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.