8.使用GDI+画图

1.DrawIcon
DrawIcon(Icon icon, Rectangle targetRect)
DrawIcon(Icon icon, int x, int y)
DrawIconUnstretched(Icon icon, Rectangle targetRect)
private void Form1_Paint(object sender, PaintEventArgs e)
{
    //创建画板从Paint事件中的直接引用Graphics对象
    Graphics graphics = e.Graphics;
    graphics.Clear(Color.Black);

    //创建一个Ico
    Icon newIcon = new Icon("SampIcon.ico");

    Rectangle rect = new Rectangle(20, 20, 50, 50);
    e.Graphics.DrawIcon(newIcon, rect);

    e.Graphics.DrawIcon(newIcon, 80, 20);

    //宽度和高度不会对原图照成影响
    Rectangle rect2 = new Rectangle(120, 20, 100, 100);
    e.Graphics.DrawIconUnstretched(newIcon, rect2);
}

2.DrawImage
DrawImage 方法 (Image, Point)
DrawImage 方法 (Image, Int32, Int32)

DrawImage 方法 (Image, PointF)
DrawImage 方法 (Image, Single, Single)

DrawImage 方法 (Image, Point[])
DrawImage 方法 (Image, PointF[])
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Image newImage = Image.FromFile("SampImag.png");
            Point ulCorner = new Point(100, 100);
            e.Graphics.DrawImage(newImage, ulCorner);
        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Image newImage = Image.FromFile("SampImag.png");

            Point ulCorner = new Point(100, 100);
            Point urCorner = new Point(550, 100);
            Point llCorner = new Point(150, 250);
            Point[] destPara = { ulCorner, urCorner, llCorner };

            //Points 参数指定平行四边形的三个点。 三个 Point 结构表示平行四边形的左上角、右上角和左下角。
            //可从前三个点推断出第四个点以形成一个平行四边形。
            //缩放和剪切 image 参数表示的图像,以适合 Points参数指定的平行四边形的形状。
            e.Graphics.DrawImage(newImage, destPara);
        }

DrawImage 方法 (Image, Rectangle)
DrawImage 方法 (Image, Int32, Int32, Int32, Int32)
DrawImage 方法 (Image, RectangleF)
DrawImage 方法 (Image, Single, Single, Single, Single)
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Image newImage = Image.FromFile("SampImag.png");
            Rectangle destRect = new Rectangle(100, 100, 450, 150);
            // 由 image 对象表示的图像被缩放为 rect 矩形的尺寸
            e.Graphics.DrawImage(newImage, destRect);
        }

        //按照第三个参数所指定从图片中取出一个矩形部分,然后将这个矩形部分放到第二个参数指定的部分来显示
        //第二个参数可以是Point[]的平行四边形,也可以是Rectangle的矩形。
        //第四个参数用于控制图形绘制单位
        DrawImage 方法 (Image, Point[], Rectangle, GraphicsUnit)
        DrawImage 方法 (Image, PointF[], RectangleF, GraphicsUnit)
        DrawImage 方法 (Image, Rectangle, Rectangle, GraphicsUnit)
        DrawImage 方法 (Image, RectangleF, RectangleF, GraphicsUnit)

        //下面的是用int或folat,是在指定的位置绘制图像的一部分,上面的是在指定的区域
        DrawImage 方法 (Image, Int32, Int32, Rectangle, GraphicsUnit)
        DrawImage 方法 (Image, Single, Single, RectangleF, GraphicsUnit)
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Image newImage = Image.FromFile("SampImag.png");

            Point ulCorner = new Point(100, 100);
            Point urCorner = new Point(325, 100);
            Point llCorner = new Point(150, 250);
            Point[] destPara = { ulCorner, urCorner, llCorner };

            Rectangle srcRect = new Rectangle(50, 50, 150, 150);
            GraphicsUnit units = GraphicsUnit.Pixel;

            e.Graphics.DrawImage(newImage, destPara, srcRect, units);
        }

DrawImage 方法 (Image, Point[], Rectangle, GraphicsUnit, ImageAttributes)
DrawImage 方法 (Image, PointF[], RectangleF, GraphicsUnit, ImageAttributes)

ImageAttributes ,它指定 image 对象的重新着色和伽玛信息。 

private void Form1_Paint(object sender, PaintEventArgs e)
{
     Image newImage = Image.FromFile("SampImag.png");
           
     Rectangle srcRect = new Rectangle(50, 50, 150, 150);
     GraphicsUnit units = GraphicsUnit.Pixel;

     Point ulCorner2 = new Point(325, 100);
     Point urCorner2 = new Point(550, 100);
     Point llCorner2 = new Point(375, 250);
     Point[] destPara2 = { ulCorner2, urCorner2, llCorner2 };

     ImageAttributes imageAttr = new ImageAttributes();
     imageAttr.SetGamma(4.0F);

     e.Graphics.DrawImage(newImage, destPara2, srcRect, units, imageAttr);
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值