C# DrawImage函数

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);
              }

  • 3
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值