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

           }

    最后缩略成功

    如果你总是等来等去,最终什么都没有等到
  • 相关阅读:
    mysql子查询不支持limit问题解决
    mysql在把子查询结果作为删除表中数据的条件,mysql不允许在子查询的同时删除原表数据
    mysql多表删除指定记录
    px、em、rem、%、vw、vh、vm这些单位的区别
    golang 使用 gRPC
    golang 实现定时任务 cron
    golang 配置文件解析神器--viper
    GO语言异常处理机制
    分析源码理解GO语言文件操作
    用python刷算法--堆排序算法
  • 原文地址:https://www.cnblogs.com/jiaguo648517982/p/3104782.html
Copyright © 2011-2022 走看看