zoukankan      html  css  js  c++  java
  • 图片各种旋转、改变大小

    1、各种旋转、改变大小

     

    注意:先要添加画图相关的

    using

    引用。

     

    //

    向右旋转图像

    90

    °代码如下

    private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) 

    Graphics g = e.Graphics; 

    Bitmap bmp = new Bitmap("rama.jpg");//

    加载图像

     

    g.FillRectangle(Brushes.White, this.ClientRectangle);//

    填充窗体背景为白色

     

    Point[] destinationPoints = { 

    new Point(100, 0), // destination for upper-left point of original 

    new Point(100, 100),// destination for upper-right point of original 

    new Point(0, 0)}; // destination for lower-left point of original 

    g.DrawImage(bmp, destinationPoints); 

     

    //

    旋转图像

    180

    °代码如下

    private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) 

    Graphics g = e.Graphics; 

    Bitmap bmp = new Bitmap("rama.jpg"); 

    g.FillRectangle(Brushes.White, this.ClientRectangle); 

    Point[] destinationPoints = { 

    new Point(0, 100), // destination for upper-left point of original 

    new Point(100, 100),// destination for upper-right point of original 

    new Point(0, 0)}; // destination for lower-left point of original 

    g.DrawImage(bmp, destinationPoints); 

     

    //

    图像切变代码

    private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) 

    Graphics g = e.Graphics; 

    Bitmap bmp = new Bitmap("rama.jpg"); 

    g.FillRectangle(Brushes.White, this.ClientRectangle); 

    Point[] destinationPoints = { 

    new Point(0, 0), // destination for upper-left point of original 

    new Point(100, 0), // destination for upper-right point of original 

    new Point(50, 100)};// destination for lower-left point of original 

    g.DrawImage(bmp, destinationPoints); 

     

    //

    图像截取

    private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) 

     

    Graphics g = e.Graphics; 

    Bitmap bmp = new Bitmap("rama.jpg"); 

    g.FillRectangle(Brushes.White, this.ClientRectangle); 

    Rectangle sr = new Rectangle(80, 60, 400, 400);//

    要截取的矩形区域

     

    Rectangle dr = new Rectangle(0, 0, 200, 200);//

    要显示到

    Form

    的矩形区域

     

    g.DrawImage(bmp, dr, sr, GraphicsUnit.Pixel); 

     

    //

    改变图像大小

    private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) 

    Graphics g = e.Graphics; 

    Bitmap bmp = new Bitmap("rama.jpg"); 

    g.FillRectangle(Brushes.White, this.ClientRectangle); 

    int width = bmp.Width; 

    int height = bmp.Height; 

    // 

    改变图像大小使用低质量的模式

     

    g.InterpolationMode = InterpolationMode.NearestNeighbor; 

    g.DrawImage(bmp, new Rectangle(10, 10, 120, 120), // source rectangle 

    new Rectangle(0, 0, width, height), // destination rectangle 

    GraphicsUnit.Pixel); 

    // 

    使用高质量模式

     

    //g.CompositingQuality = CompositingQuality.HighSpeed; 

    g.InterpolationMode = InterpolationMode.HighQualityBicubic; 

    g.DrawImage( 

    bmp, 

    new Rectangle(130, 10, 120, 120), 

     

    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("rama.jpg"); 

    g.FillRectangle(Brushes.White, this.ClientRectangle); 

    bmp.SetResolution(300f, 300f); 

    g.DrawImage(bmp, 0, 0); 

    bmp.SetResolution(1200f, 1200f); 

    g.DrawImage(bmp, 180, 0); 

     

    //

    GDI+

    画图

     

     

    private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) 

    Graphics gForm = e.Graphics; 

    gForm.FillRectangle(Brushes.White, this.ClientRectangle); 

    for (int i = 1; i <= 7; ++i) 

    //

    在窗体上面画出橙色的矩形

     

    Rectangle r = new Rectangle(i*40-15, 0, 15, 

    this.ClientRectangle.Height); 

    gForm.FillRectangle(Brushes.Orange, r); 

    //

    在内存中创建一个

    Bitmap

    并设置

    CompositingMode 

    Bitmap bmp = new Bitmap(260, 260, 

    System.Drawing.Imaging.PixelFormat.Format32bppArgb); 

    Graphics gBmp = Graphics.FromImage(bmp); 

    gBmp.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy; 

    // 

    创建一个带有

    Alpha

    的红色区域

     

    // 

    并将其画在内存的位图里面

     

    Color red = Color.FromArgb(0x60, 0xff, 0, 0); 

    Brush redBrush = new SolidBrush(red); 

    gBmp.FillEllipse(redBrush, 70, 70, 160, 160); 

    // 

    创建一个带有

    Alpha

    的绿色区域

     

    Color green = Color.FromArgb(0x40, 0, 0xff, 0); 

    Brush greenBrush = new SolidBrush(green); 

    gBmp.FillRectangle(greenBrush, 10, 10, 140, 140); 

    //

    在窗体上面画出位图

     

    now draw the bitmap on our window 

    gForm.DrawImage(bmp, 20, 20, bmp.Width, bmp.Height); 

    // 

    清理资源

     

    bmp.Dispose(); 

    gBmp.Dispose(); 

    redBrush.Dispose(); 

    greenBrush.Dispose(); 

     

     
     
    评价文档:
    /25
    1 下载券�下载加入VIP,免劵下载本文
    复制 | 搜索 | 翻译 | 百科 | 
  • 相关阅读:
    leetcode教程系列——Binary Tree
    《Ranked List Loss for Deep Metric Learning》CVPR 2019
    《Domain Agnostic Learning with Disentangled Representations》ICML 2019
    Pytorch从0开始实现YOLO V3指南 part5——设计输入和输出的流程
    Pytorch从0开始实现YOLO V3指南 part4——置信度阈值和非极大值抑制
    Pytorch从0开始实现YOLO V3指南 part3——实现网络前向传播
    Pytorch从0开始实现YOLO V3指南 part2——搭建网络结构层
    Pytorch从0开始实现YOLO V3指南 part1——理解YOLO的工作
    让我佩服的人生 文章
    win8.1配置cordova+ionic等一系列东西
  • 原文地址:https://www.cnblogs.com/ylldbk/p/5332643.html
Copyright © 2011-2022 走看看