Programming/Language

[C#] Drawing on picture box images

appHunter 2015. 5. 8. 17:24

Drawing on picture box images


출처 : http://www.codeproject.com/Tips/318900/Drawing-on-picture-box-images

public void drawEllipse(PictureBox pb, int x, int y, int w, int h, float Bwidth,Color col)
        {
            //refresh the picture box
            pb.Refresh();
            //create a graphics object
            Graphics g = pb.CreateGraphics();
            //create a pen object
            Pen p = new Pen(col, Bwidth);
            //draw Ellipse
            g.DrawEllipse(p, x, y, w, h);
            //dispose pen and graphics object
            p.Dispose();
            g.Dispose();
        }


public void drawline(PictureBox pb, Point p1, Point p2, float Bwidth,Color c1)
        {
            //refresh the picture box
            pb.Refresh(); 
            //create a new Bitmap object
            Bitmap map=(Bitmap)pb.Image;  
            //create a graphics object
            Graphics g = Graphics.FromImage(map);  
            //create a pen object and setting the color and width for the pen
            Pen p = new Pen(c1, Bwidth);  
            //draw line between  point p1 and p2
            g.DrawLine(p, p1, p2);  
            pb.Image = map;  
            //dispose pen and graphics object
            p.Dispose();  
            g.Dispose();
        }