zoukankan      html  css  js  c++  java
  • Picturebox实现图片的缩放

    程序中要弄个简单的图片查看器,可以按比例缩放大小的,当然可以调用windows的图片查看器,不过想想还是自己动手弄个简单的吧。。

    缩放操作在Picturebox重绘的时候触发执行。如下

    代码
    1 //重绘处理部分
    2   private void pipeImagePictureBox_Paint(object sender, PaintEventArgs e)
    3 {
    4 try
    5 {
    6 if (pipeImagePath != "")
    7 {
    8 pipeImage = new Bitmap(pipeImagePath);
    9 }
    10 Graphics g = e.Graphics;
    11 //设置高质量插值法
    12   g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
    13 //设置高质量,低速度呈现平滑程度
    14   g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
    15 g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
    16 //消除锯齿
    17   g.SmoothingMode = SmoothingMode.AntiAlias;
    18
    19 float fx = (float)(this.pipeImageZoomNumericUpDown.Value / 100);
    20 float fy = (float)(this.pipeImageZoomNumericUpDown.Value / 100);
    21 int w = (int)(pipeImage.Width * fx), h = (int)(pipeImage.Height * fy);
    22 pipeImagePictureBox.Width = w;
    23 pipeImagePictureBox.Height = h;
    24 int W = (int)(pipeImagePanel.Width), H = (int)(pipeImagePanel.Height);
    25 pipeImagePictureBox.Location = new System.Drawing.Point((W - w) / 2, (H - h) / 2);
    26 pipeImagePictureBox.Size = new Size(w,h);
    27
    28 Rectangle newRectangle = new Rectangle(0, 0, w, h);
    29 g.DrawImage(pipeImage, newRectangle);
    30 }
    31 catch (Exception ex)
    32 {
    33 //pipeImagePictureBox.Image = null;
    34   }
    35 }

    当然,除了缩放还有其他的要做。。

  • 相关阅读:
    linux上安装mysql
    linux 上nginx配置
    js人民币数字转大写
    pm2常用命令
    基于redis实现分布式锁
    Enterprise Architect 14破解版 安装包 安装教程
    一些有用的链接
    Linux安装Zookeeper
    根据朋友圈的网易云音乐分享找到人
    我的待做事项
  • 原文地址:https://www.cnblogs.com/njucslzh/p/1872316.html
Copyright © 2011-2022 走看看