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);  

           }

    最后缩略成功

    如果你总是等来等去,最终什么都没有等到
  • 相关阅读:
    20200301(4)
    网络工程横道图
    20200229追根溯源(3)
    20200229(2)
    追根溯源 (1)
    20200228 down(0)
    20200228
    7-7 古风排版 (20分)
    不写了天梯赛 屁股疼死了
    字符串翻转(面试题2)
  • 原文地址:https://www.cnblogs.com/jiaguo648517982/p/3104782.html
Copyright © 2011-2022 走看看