winfrom后台:
private void button1_Click(object sender, EventArgs e)
{
//Graphics g = this.CreateGraphics();//这里图像对象的初始化,不能使用new的形式
//在初始化一个对象的时候,必须关联一个图像输出的设备。
//g.DrawLine(Pens.Red,0,0,100,100);
Graphics g = pictureBox1.CreateGraphics();
g.DrawRectangle(Pens.Blue,10,10,60,100);
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = this.CreateGraphics();//这里图像对象的初始化,不能使用new的形式
//在初始化一个对象的时候,必须关联一个图像输出的设备。
g.DrawLine(Pens.Red,0,0,100,100);
e.Graphics.DrawRectangle(Pens.Blue, 10, 10, 60, 100);
}
private void button2_Click(object sender, EventArgs e)
{
if (this.openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
Image img = Image.FromFile(this.openFileDialog1.FileName);
Graphics g = Graphics.FromImage(img);
//在图片上画两条直线
Pen pen1 = new Pen(Color.Black, 10);
g.DrawLine(pen1, 0, 200, 670, 200);
g.DrawLine(Pens.Red, 0, 495, 670, 495);
//在图片上画圆
Color c1=Color.FromArgb(255,0,0);
Pen pen2 = new Pen(c1, 20);
g.DrawEllipse(pen2,0,40,40,40);
g.DrawEllipse(Pens.Green, 0, 40, 40, 40);
g.DrawEllipse(Pens.Green, 40, 40, 40, 40);
g.DrawEllipse(Pens.Green, 80, 40, 40, 40);
g.DrawEllipse(Pens.Green, 120, 40, 40, 40);
//透明度
Color c2 = Color.FromArgb(50, 200, 100, 210);
Pen pen3 = new Pen(c2, 30);
g.DrawEllipse(pen3, 10, 300, 120, 120);
//用画刷填充一个圆
g.FillEllipse(Brushes.Green, 200, 40, 40, 40);
g.FillEllipse(Brushes.Green, 240, 40, 40, 40);
g.FillEllipse(Brushes.Green, 280, 40, 40, 40);
g.FillEllipse(Brushes.Green, 320, 40, 40, 40);
//画刷的使//用
Brush b = Brushes.Gray;
g.FillEllipse(b,400,40,80,80);
Color c3 = Color.FromArgb(255,0,0);
SolidBrush sb = new SolidBrush(c3);
g.FillEllipse(sb,300,90,180,180);
Image img1 = Image.FromFile("F:\\ASP.NET高级\\商炳奇\\12-26\\12-26-1\\images\\1.png");
TextureBrush b1 = new TextureBrush(img1);
g.FillPie(b1, 0, 0, 400, 400, 180, 360);
g.FillRectangle(b1, 300, 300, 500, 500);
//画一个弧形
g.DrawPie(Pens.Green,30,40,400,400,90,360);
g.DrawArc(Pens.Blue, 300, 40, 400, 400, 180, 180);
//画出字
g.DrawString("CSDN", new Font("宋体", 180), b1, 200, 0);
//画出图片
g.DrawImage(img1, img.Width - img1.Width - 20, img.Height - img1.Height - 20,);
img.Save("H:\\meinv.png");
this.pictureBox1.Image = img;
}
}