How to save a picture?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MohammedAli07
    New Member
    • Apr 2010
    • 2

    How to save a picture?

    I have done some graphics work and I need to save it to a file.
    Mu work is a Polygon, How can I save it to a file ?
    I've read some answers but I need a full explanation for the way, please.
  • GaryTexmo
    Recognized Expert Top Contributor
    • Jul 2009
    • 1501

    #2
    Hmm, if you're doing custom rendering (ie, GDI+) on a form, I think you might have to take a screenshot of the space your graphic takes up. If that works for you, google around. There's code that shows you how to make calls to the windows DLLs to capture a portion of the screen.

    That's all I can think of right now... maybe other people have better ideas :)

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      Yup if you're drawing directly on a control (using the Graphics object for that control) then you have to rely on a screenshot.
      If instead you draw on a graphics object that is from an Image(Bitmap) object, then you have direct .Save() functions

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        However, if your shape is made up of points then you can save the list of points. This would be a simplistic version of a drawing program such as Adobe Illustrator, versus a painting program like Adobe Photoshop that saves bitmaps.

        Ideally your program would have a class called "Shape".
        From that you inherit to make a class called "Oval", another called "rectangle" and so on. The file you save would be a serialization of your shapes.

        This way you can select a shape and move/change/delete it.
        As apposed to just painting on a canvas that cannot be easily altered.

        Without just handing it all to you, this should give you the idea
        Code:
        class Shape
        {
             List<Point> Points;
             Color FillColor;
             Color LineColor;
             string FillPattern;
        }
        
        class Oval : Shape
        {
             int Diameter;
        }
        Since the Oval inherits from Shape, it contains all of the methods and properties of a Shape. So you don't have to define a LineColor property in your circle, and again in your square, and again in your polygon etc. Yet individual shapes can add to the basic properties of their parent, such as the Oval gaining a Diameter.

        Comment

        • MohammedAli07
          New Member
          • Apr 2010
          • 2

          #5
          Hello Guys
          thanks for ur response
          This is my code.
          Code:
          private void Form1_Paint(object sender, PaintEventArgs e)
                      {
          
                          System.Drawing.Graphics GraphicsObj;
                          GraphicsObj = this.CreateGraphics();
                          SolidBrush bb = new SolidBrush(Color.Red);
                          Pen MyPen = new Pen(Color.Red, 2);
                          Point[] points = new Point[5];
                          System.Random random = new Random();
          
                          int i = 0;
                          int rand1, rand2;
                          for (i = 0; i < 5; i++)
                          {
                              rand1 = random.Next(200);
                              rand2 = random.Next(200);
                              points[i] = new Point(rand1, rand2);
                              GraphicsObj.FillRectangle(bb, rand1, rand2, 1, 1);
                            
          
                          }
                        
                          GraphicsObj.DrawPolygon(MyPen, points);
                          GraphicsObj.FillPolygon(bb, points);
                         Bitmap b =new Bitmap  (200, 200);
                          GraphicsObj = Graphics.FromImage(b);
                      }
          Just asking if I could use the Save() function to save my work?
          Plus, How can I use it ?

          Comment

          • tlhintoq
            Recognized Expert Specialist
            • Mar 2008
            • 3532

            #6
            Is this supposed to be an override of the form's .Paint method?

            Try making a new Image....
            Do your painting on the new Image...
            Now you have an Image you can Image.Save(stri ng Path);
            Then make the image the Background.Imag e of the form

            Comment

            • Plater
              Recognized Expert Expert
              • Apr 2007
              • 7872

              #7
              You've got this line:
              GraphicsObj = this.CreateGrap hics();
              Which is making a Graphics object from the control (so no Save() method)
              If instead you created a Graphics object from an Image object, you could carry on with how you've done it so far. Then just draw that image onto your Form.
              The Image object is what has the Save() function.

              Comment

              Working...