zoukankan      html  css  js  c++  java
  • 简单的GDI+处理图片大小(C#代码)

      /// <summary>
            
    /// 缩放图片
            
    /// </summary>
            
    /// <param name="img">原图片</param>
            
    /// <param name="xWith">缩放宽比例,如果想缩小图片,小于100</param>
            
    /// <param name="yHeight">缩放高比例</param>
            
    /// <returns>返回处理后图片</returns>

            public Image scaleImg(System.Drawing.Image img, int xWith, int yHeight)
            
    {
                
    //计算处理后图片宽
                int i = Convert.ToInt32(img.Width * xWith / 100);
                
    //计算处理后图片高
                int j = Convert.ToInt32(img.Height * yHeight / 100);
                
    //格式化图片
                System.Drawing.Image imgScale = new System.Drawing.Bitmap(i, j, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                System.Drawing.Graphics g 
    = System.Drawing.Graphics.FromImage(imgScale);
                System.Drawing.Rectangle srcRect 
    = new System.Drawing.Rectangle(00, img.Width, img.Height);
                System.Drawing.Rectangle desRect 
    = new System.Drawing.Rectangle(00, imgScale.Width, imgScale.Height);
                g.Clear(System.Drawing.Color.White);
                g.DrawImage(img, desRect, srcRect, System.Drawing.GraphicsUnit.Pixel);
                
    //处理后的图片另存
                imgScale.Save("E:\\1111.jpg", System.Drawing.Imaging.ImageFormat.Gif);
                g.Dispose();
                
    return imgScale;
            }
     
  • 相关阅读:
    aix lvm_lv_vg
    Centos6.5 telnet wireshark
    Qt开发初步,循序渐进,preRequest for 蓝图逆袭
    CentOs文件实时同步
    Qt GUI开发实战初期
    linux环境开发私房菜
    linux GUI程序开发
    Centos6.5 Qt4开发 Cannot find -lGL QApplication not file or dir
    Centos6.5升级gcc for qt5.3.1
    对Socket CAN的理解(5)——【Socket CAN控制器的初始化过程】
  • 原文地址:https://www.cnblogs.com/whitetiger/p/1235341.html
Copyright © 2011-2022 走看看