Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Graphics to File

Graphics to File

Scheduled Pinned Locked Moved C#
graphicscomhelptutorialquestion
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pmartike
    wrote on last edited by
    #1

    How to save into a file a graphics? I tried this but not working :( Graphics g = pictureBox1.CreateGraphics(); Pen p = new Pen(Color.Black); g.DrawRectangle(p, 1, 1, 100, 20); Bitmap bit = new Bitmap(482, 150, g); bit.Save("c:\\image.bmp"); And if i draw something into a picturebox, how to save it into a file? I tried this but not working :( Graphics g = pictureBox1.CreateGraphics(); Pen p = new Pen(Color.Black); gg.DrawRectangle(p, 1, 1, 100, 50); gg.DrawRectangle(p, 2, 10, 50, 30); Bitmap bb = new Bitmap(pictureBox1.Image); bb.Save("c:\\image.bmp"); Help me please!

    http://pmartike.deviantart.com/

    G C Z H 4 Replies Last reply
    0
    • P pmartike

      How to save into a file a graphics? I tried this but not working :( Graphics g = pictureBox1.CreateGraphics(); Pen p = new Pen(Color.Black); g.DrawRectangle(p, 1, 1, 100, 20); Bitmap bit = new Bitmap(482, 150, g); bit.Save("c:\\image.bmp"); And if i draw something into a picturebox, how to save it into a file? I tried this but not working :( Graphics g = pictureBox1.CreateGraphics(); Pen p = new Pen(Color.Black); gg.DrawRectangle(p, 1, 1, 100, 50); gg.DrawRectangle(p, 2, 10, 50, 30); Bitmap bb = new Bitmap(pictureBox1.Image); bb.Save("c:\\image.bmp"); Help me please!

      http://pmartike.deviantart.com/

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      Standard question #1: What do you mean by "not working"? Standard question #2: What error message do you get? The CreateGraphics method creates a Graphics object for drawing on the control. There is no specific CreateGraphics method that creates a Graphics object for drawing on the image in a PictureBox. You are just drawing on the screen, that does not affect the image in the PictureBox. You have to create a Graphics object for the bitmap so that you can draw the graphics on the bitmap instead of on the screen.

      --- single minded; short sighted; long gone;

      P 1 Reply Last reply
      0
      • P pmartike

        How to save into a file a graphics? I tried this but not working :( Graphics g = pictureBox1.CreateGraphics(); Pen p = new Pen(Color.Black); g.DrawRectangle(p, 1, 1, 100, 20); Bitmap bit = new Bitmap(482, 150, g); bit.Save("c:\\image.bmp"); And if i draw something into a picturebox, how to save it into a file? I tried this but not working :( Graphics g = pictureBox1.CreateGraphics(); Pen p = new Pen(Color.Black); gg.DrawRectangle(p, 1, 1, 100, 50); gg.DrawRectangle(p, 2, 10, 50, 30); Bitmap bb = new Bitmap(pictureBox1.Image); bb.Save("c:\\image.bmp"); Help me please!

        http://pmartike.deviantart.com/

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        pmartike wrote:

        pictureBox1.CreateGraphics();

        To further clarify, you should never do this 1 - it's a waste of a picture box, the picture box does nothing 2 - if your form is obscured, what you drew will be erased Draw in your paint event, or create a Bitmap and assign it to the picture box. Draw on it first if you want to, and save it, if you want to do that.

        pmartike wrote:

        Bitmap bb = new Bitmap(pictureBox1.Image);

        The issue here is that there is no image inside the picture box, you need to put one in there, and even if you do, CreateGraphics won't do anything to it. It's more like you are drawing on a layer above the control, a layer that is not permanent.

        Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

        1 Reply Last reply
        0
        • P pmartike

          How to save into a file a graphics? I tried this but not working :( Graphics g = pictureBox1.CreateGraphics(); Pen p = new Pen(Color.Black); g.DrawRectangle(p, 1, 1, 100, 20); Bitmap bit = new Bitmap(482, 150, g); bit.Save("c:\\image.bmp"); And if i draw something into a picturebox, how to save it into a file? I tried this but not working :( Graphics g = pictureBox1.CreateGraphics(); Pen p = new Pen(Color.Black); gg.DrawRectangle(p, 1, 1, 100, 50); gg.DrawRectangle(p, 2, 10, 50, 30); Bitmap bb = new Bitmap(pictureBox1.Image); bb.Save("c:\\image.bmp"); Help me please!

          http://pmartike.deviantart.com/

          Z Offline
          Z Offline
          zeeShan anSari
          wrote on last edited by
          #4

          Hi, your & my problem both are same ,read my today(june,27) post "Problem about bitmap in Visual Studio C Sharp.NET ?" i solve my half problem by following code: Bitmap bmp = new Bitmap(pictureBox2.Width, pictureBox2.Height); Graphics g = Graphics.FromImage(bmp); Pen p = new Pen(Color.Red, 5); g.DrawEllipse(p, e.X, e.Y, 5, 7); pictureBox2.Image = bmp; *first read my post, if you get any solution then please inform me

          P 1 Reply Last reply
          0
          • P pmartike

            How to save into a file a graphics? I tried this but not working :( Graphics g = pictureBox1.CreateGraphics(); Pen p = new Pen(Color.Black); g.DrawRectangle(p, 1, 1, 100, 20); Bitmap bit = new Bitmap(482, 150, g); bit.Save("c:\\image.bmp"); And if i draw something into a picturebox, how to save it into a file? I tried this but not working :( Graphics g = pictureBox1.CreateGraphics(); Pen p = new Pen(Color.Black); gg.DrawRectangle(p, 1, 1, 100, 50); gg.DrawRectangle(p, 2, 10, 50, 30); Bitmap bb = new Bitmap(pictureBox1.Image); bb.Save("c:\\image.bmp"); Help me please!

            http://pmartike.deviantart.com/

            H Offline
            H Offline
            Hesham Yassin
            wrote on last edited by
            #5

            serialize it

            1 Reply Last reply
            0
            • G Guffa

              Standard question #1: What do you mean by "not working"? Standard question #2: What error message do you get? The CreateGraphics method creates a Graphics object for drawing on the control. There is no specific CreateGraphics method that creates a Graphics object for drawing on the image in a PictureBox. You are just drawing on the screen, that does not affect the image in the PictureBox. You have to create a Graphics object for the bitmap so that you can draw the graphics on the bitmap instead of on the screen.

              --- single minded; short sighted; long gone;

              P Offline
              P Offline
              pmartike
              wrote on last edited by
              #6

              Thanks, you're right :) i solved the problem...

              http://pmartike.deviantart.com/

              1 Reply Last reply
              0
              • Z zeeShan anSari

                Hi, your & my problem both are same ,read my today(june,27) post "Problem about bitmap in Visual Studio C Sharp.NET ?" i solve my half problem by following code: Bitmap bmp = new Bitmap(pictureBox2.Width, pictureBox2.Height); Graphics g = Graphics.FromImage(bmp); Pen p = new Pen(Color.Red, 5); g.DrawEllipse(p, e.X, e.Y, 5, 7); pictureBox2.Image = bmp; *first read my post, if you get any solution then please inform me

                P Offline
                P Offline
                pmartike
                wrote on last edited by
                #7

                i can't find your post :( i resolved my problem too: Bitmap bit = new Bitmap(244, 200); Graphics g = Graphics.FromImage(bit); g.DrawRectangle(WhitePen, 10,10, 100, 50); bit.Save("c:\\image.bmp"); Can you give a link with your post?

                http://pmartike.deviantart.com/

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups