1. DrawImage
6.1DrawImage (Image, int, int)
6.1 DrawImage(Image, Rectangle)
6.2DrawImage (Image, Rectangle[destRect ], Rectangle[srcRect ], GraphicsUnit)
在指定位置并且按指定大小绘制指定的 Image 对象的指定部分。
Rectangle[destRect ] 它指定所绘制图像的位置和大小。将图像进行缩放以适合该矩形。
Rectangle[srcRect ] 它指定 image 对象中要绘制的部分。
用于插补控制图像质量;剪切图像
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{//插补控制图像质量
Graphics g = e.Graphics;
Bitmap bmp = new Bitmap("A006.jpg");
g.FillRectangle(Brushes.White,this.ClientRectangle);
int width = bmp.Width;
int height = bmp.Height;
g.DrawImage(
bmp,
new Rectangle(10,10,200,200),
new Rectangle(0,0,width,height),
GraphicsUnit.Pixel);
g.InterpolationMode = InterpolationMode.NearestNeighbor;
g.DrawImage(
bmp,
new Rectangle(10,250,200,200),
new Rectangle(0,0,width,height),
GraphicsUnit.Pixel);
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.DrawImage(
bmp,
new Rectangle(250,250,200,200),
new Rectangle(0,0,width,height),
GraphicsUnit.Pixel);
}
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{//剪切图像
Graphics g = e.Graphics;
Bitmap bmp = new Bitmap("A006.jpg");
g.FillRectangle(Brushes.White,this.ClientRectangle);
int width = bmp.Width;
int height = bmp.Height;
g.DrawImage(
bmp,
new Rectangle(10,10,200,200),
new Rectangle(50,50,150,150),
GraphicsUnit.Pixel);
}
6.3 DrawImage(image, Point[3]) 可用于图像变形,翻转,旋转
第一点指定左上角坐标
第二点指定右上角坐标
第三点指定左下角坐标
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{//图像变形
Graphics g = e.Graphics;
Bitmap bmp = new Bitmap("A006.jpg");
g.FillRectangle(Brushes.White,this.ClientRectangle);
Point[] destinationPoints = {
new Point(0,0),
new Point(100,0),
new Point(50,100)};
g.DrawImage(bmp,destinationPoints);
}