zoukankan      html  css  js  c++  java
  • 让图片不变形

    •  #region 让图片不变形         /// <summary>         /// 小图标等比例缩小         /// </summary>         /// <param name="_files"></param>         /// <returns></returns>         private ImageList GetImageFrom2(string[] _files)         {             ImageList list = new ImageList();

                  int picWidth;             int picHeight;             int _iconW = 60;             int _iconH = 80;             int _picTop;             int _picLeft;             Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);             Bitmap myBitmap = null;             Image _tempImage;             for (int i = 0; i < _files.Length; i++)             {

                      myBitmap = new Bitmap(_files[i]);                 CalateSize(myBitmap.Width, myBitmap.Height, _iconW, _iconH, out picWidth, out picHeight);                 Image myThumbnail = myBitmap.GetThumbnailImage(picWidth, picHeight, myCallback, IntPtr.Zero);

                      //第一步                 Bitmap bp = new Bitmap(_iconW, _iconH);                 //第二步                 Graphics g = Graphics.FromImage(bp);                 g.Clear(Color.White);                 g.DrawImage(myThumbnail, (_iconW - picWidth) / 2, (_iconH - picHeight) / 2);                 list.Images.Add(_files[i], (Image)bp);                 list.ImageSize = new Size(_iconW, _iconH);             }             return list;         }         public bool ThumbnailCallback()         {             return false;         }         /// <summary>         /// 获取小图标不变形的大小         /// </summary>         /// <param name="picW"></param>         /// <param name="picH"></param>         /// <param name="iconW"></param>         /// <param name="incoH"></param>         /// <param name="_w"></param>         /// <param name="_h"></param>         public void CalateSize(int picW, int picH, int iconW, int incoH, out int _w, out int _h)         {             int _a = picW;  // 2488             int _b = picH;  // 4288             int _c = iconW;  //60             int _d = incoH;  //80             if ((_a / _b) > (_c / _d))             {                 _w = iconW;  //40                 _h = (_b * iconW / _a);             }             else             {                 _h = incoH;                 _w = (_a * incoH / _b);             }         }

              #endregion  让图片不变形

  • 相关阅读:
    eclipse中解决update maven之后jre被改成1.5的问题
    Navicat for MySQL密鈅
    静态创建和动态创建对象的区别
    vector相关操作总结
    C++的编码技巧相关总结
    关于VS中未经处理的异常的梳理
    头文件用于声明而不是定义
    SQL单表查询练习部分总结
    delete对象时会自动调用类的析构函数
    SQL中的sum在何时会返回为null
  • 原文地址:https://www.cnblogs.com/szlixin/p/4949776.html
Copyright © 2011-2022 走看看