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);
  • 相关阅读:
    Aop——面向切面编程
    认识界上最流行的Api框架——swagger
    手把手SSM框架实战
    面试题
    重新拾起JavaSE的日子
    使用IntelliJ IDEA创建第一个Maven项目
    Java面试必考题
    Vue项目——去哪网(首页部分)
    Vue项目的准备
    vue.js ③
  • 原文地址:https://www.cnblogs.com/lucika/p/4745509.html
Copyright © 2011-2022 走看看