0

i have the following code to generate my bitmap image using C#. i just want to know how i can save the output image to my desktop directory instead of showing to my picture box?

        Image bmp = new Bitmap(100, 100);
          Graphics g = Graphics.FromImage(bmp);
          g.DrawString(randomString, myFont, new SolidBrush(Color.Black), new PointF(0, 0));
          pictureBox1.Image = bmp;
CowBoy
  • 185
  • 5
  • 19
  • how are g and bmp related? You might glean something here http://stackoverflow.com/questions/12909905/saving-image-to-file – wruckie Jan 25 '14 at 22:20
  • only that? no more syntax and where doeas it save the image? – CowBoy Jan 25 '14 at 22:29
  • 1
    @CowBoy Just type `Image.Save` to google and go the first msdn link. It also contains an example. Is this so hard? – L.B Jan 25 '14 at 22:45

1 Answers1

0

Try this: pictureBox1.Image.Save("your path", ImageFormat.your_format);

You will need this reference: using System.Drawing.Imaging;

Michał
  • 2,202
  • 2
  • 17
  • 33
  • when you write `ImageFormat.` intelliSense should give you suggestions, for example `ImageFormat.Jpeg` – Michał Jan 25 '14 at 22:30
  • do i need to add any reference? and what can i put to save it for example on my desktop (general address that works for all computer) – CowBoy Jan 25 '14 at 22:33
  • @CowBoy answered that in an edit. Add: `using System.Drawing.Imaging;` – Michał Jan 25 '14 at 22:35
  • i got it cool! but it doeasnt save it, i put "C:\Users\M.R.B\Desktop" but its giving me error – CowBoy Jan 25 '14 at 22:38
  • @CowBoy what is the error? Maybe the problem lays in "\" Try this instead `@ "C:\Users\M.R.B\Desktop\File name"`. "\" is used in Escape Sequences: http://msdn.microsoft.com/en-us/library/h21280bw.aspx – Michał Jan 25 '14 at 22:41
  • its working, just one thing, do you know why its drawing a black square? while i was Expecting to have my character font to be black not the back ground!!! – CowBoy Jan 25 '14 at 22:55
  • 1
    @CowBoy Probably that is the default bitmap color. Try this `g.Clear(Color.White)` before writing text. – Michał Jan 25 '14 at 22:58