zoukankan      html  css  js  c++  java
  • 缩略图的压缩问题

    如果宽度固定,高度等比例压缩的话,如何计算高度的问题:

    string originalImagePath;//原图的路径

    System.Drawing.Image originalImage = System.Drawing.Image.FromFile(originalImagePath);

    1.指定宽,高按比例 缩放           
      int    toheight = originalImage.Height * width / originalImage.Width; 

    2.指定高,宽按比例
      int  towidth = originalImage.Width * height / originalImage.Height;

    3.如果指定宽、高

     private static Size ResizeImage(int width, int height, int maxWidth, int maxHeight)   

          {       

         decimal MAX_WIDTH = (decimal)maxWidth;     

            decimal MAX_HEIGHT = (decimal)maxHeight;       

          decimal ASPECT_RATIO = MAX_WIDTH / MAX_HEIGHT;

                int newWidth, newHeight;        

         decimal originalWidth = (decimal)width;     

            decimal originalHeight = (decimal)height;

                if (originalWidth > MAX_WIDTH || originalHeight > MAX_HEIGHT)        

         {                

            decimal factor;            

             if (originalWidth / originalHeight > ASPECT_RATIO)      

               {                 

                 factor = originalWidth / MAX_WIDTH;            

             newWidth = Convert.ToInt32(originalWidth / factor);           

              newHeight = Convert.ToInt32(originalHeight / factor);        

             }           

          else             

        {                   

      factor = originalHeight / MAX_HEIGHT;      

                   newWidth = Convert.ToInt32(originalWidth / factor);       

                  newHeight = Convert.ToInt32(originalHeight / factor);      

               }         

        }           

      else         

        {                

    newWidth = width;      

               newHeight = height;       

          }           

      return new Size(newWidth, newHeight);  

           }

    最后缩略成功

    如果你总是等来等去,最终什么都没有等到
  • 相关阅读:
    a[::-1]相当于 a[-1:-len(a)-1:-1],也就是从最后一个元素到第一个元素复制一遍。
    +=
    map 和reduce
    赋值语句
    高阶函数
    函数式编程
    迭代器
    如何判断一个对象是可迭代对象呢?方法是通过collections模块的Iterable类型判断:
    ie11升级的过程中遇到的问题以及解决办法
    .csporj 文件部分节点解析
  • 原文地址:https://www.cnblogs.com/jiaguo648517982/p/3104782.html
Copyright © 2011-2022 走看看