• 让图片不变形


    •  #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  让图片不变形

  • 相关阅读:
    STM32如何用LCD、OLED显示浮点数
    STM32F 系列芯片 容量文件选择 startup_stm32f10x_hd
    sprintf与浮点数表示
    VSCode安装、配置
    用IDEA编写Vue
    mychart.onclick点击一次,执行多次
    软件测试和软件项目的关系
    java list model转换
    几个Java常用库
    mysql json 数组查询
  • 原文地址:https://www.cnblogs.com/szlixin/p/4949776.html
Copyright © 2020-2023  润新知