zoukankan      html  css  js  c++  java
  • 在内存中动态生成缩略图

    public void ProcessRequest (HttpContext context) {
    context.Response.ContentType = "image/jpeg";
    //url传来的图片名
    string img = context.Request.QueryString["img"];
    if (!string .IsNullOrEmpty(img))
    {
    //获取图片的物理路径
    string path = context.Request.MapPath("images/"+img);
    //加载大图
    Image big = Image.FromFile(path);

    int oldWidth = big.Width;
    int oldHeigth = big.Height;
    int newWidth = 150;
    int newHeigth = 100;
    //保持纵横比例
    if (oldWidth > oldHeigth)
    {
    newHeigth = newWidth * oldHeigth / oldWidth;
    }
    else
    {
    newWidth = newHeigth * oldWidth / oldHeigth;
    }

    //生成小图
    Bitmap bitmap = new Bitmap(newWidth,newHeigth);

    Graphics g = Graphics.FromImage(bitmap);
    //把大图,画到小图上
    g.DrawImage(big,0,0,bitmap.Width,bitmap.Height);
    //释放资源
    g.Dispose();
    //把bitmap输出到浏览器
    bitmap.Save(context.Response.OutputStream,System.Drawing.Imaging.ImageFormat.Jpeg);

    }

    }
  • 相关阅读:
    axios express设置跨域允许传递cookie
    yarn常用命令指北
    Web代理工具NProxy
    DevOps的了解
    css图片hover放大
    autoprefixer
    谈谈浏览器http缓存
    欢迎使用 MWeb
    优化关键渲染路径CRP
    chrome 61 更新
  • 原文地址:https://www.cnblogs.com/gylspx/p/1133sa.html
Copyright © 2011-2022 走看看