zoukankan      html  css  js  c++  java
  • 生成缩略图

    在原始图片大于设置图片尺寸时生成缩略图。

    int _width = 200;
    int _height = 200;
    var source = System.Drawing.Image.FromStream(new System.IO.MemoryStream(data));
    if (source.Height < _height && source.Width < _width) return new System.IO.MemoryStream(data);
    double scacle =0.10;
    if (((double) source.Height /(double)_height )>= ((double)source.Width/(double)_width))
      scacle = (double)source.Height / (double)_height;
    else
      scacle = (double)source.Width / (double)_width;
    _width = (int)(source.Width / scacle);
    _height = (int)(source.Height / scacle);
    //新建一个bmp图片
    System.Drawing.Image bitmap = new System.Drawing.Bitmap(_width, _height);
    //新建一个画板
    System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap);
    //设置高质量插值法
    g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
    //设置高质量,低速度呈现平滑程度
    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
    //清空画布并以透明背景色填充
    g.Clear(System.Drawing.Color.Transparent);
     g.DrawImage(source,
                    new System.Drawing.Rectangle(0, 0, _width, _height),
                    new System.Drawing.Rectangle(0, 0, source.Width, source.Height),
                    System.Drawing.GraphicsUnit.Pixel);
     var s = new System.IO.MemoryStream();
     bitmap.Save(s, source.RawFormat);
  • 相关阅读:
    实现 HTML页面 Table 标签分页打印
    windows定时休眠设置
    python画树
    anaconda历史版本
    枚举
    is 与 as 运算符举例
    Microsoft.ACE.OLEDB.12.0报错解决方法
    winform一个带自动完成功能的TextBox
    DWZ中整合第三方jQuery(kit日历控件)插件
    asp.net 使用NPOI,泛型反射,XML导入导出excel
  • 原文地址:https://www.cnblogs.com/lucika/p/4745509.html
Copyright © 2011-2022 走看看