zoukankan      html  css  js  c++  java
  • C# 上传生成新图片代码|C#生成图片代码

          public  void MakeSmallPic(string oldfile, string newfile,int width,int height)
            {
                System.Drawing.Image image = System.Drawing.Image.FromFile(oldfile);
                //获取原图高度和宽度
                int oldh = image.Height;
                int oldw = image.Width;
                int neww, newh;
                neww = width; newh = height;   //直接设定新图的高宽,,

                try
                {
                    System.Drawing.Image.GetThumbnailImageAbort callb = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
                    System.Drawing.Image bt = new System.Drawing.Bitmap(neww, newh);
                    System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(bt);
                    gr.Clear(Color.White);
                    gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                    gr.DrawImage(image, new Rectangle(0, 0, neww, newh), 0, 0, oldw, oldh, GraphicsUnit.Pixel);
                    switch (oldfile.Substring(oldfile.Length - 3).ToUpper())
                    {
                        case "JPG":
                            bt.Save(newfile, ImageFormat.Jpeg);
                            break;
                        case "GIF":
                            bt.Save(newfile, ImageFormat.Gif);
                            break;
                        case "PNG":
                            bt.Save(newfile, ImageFormat.Png);
                            break;
                        default:
                            bt.Save(newfile, ImageFormat.Jpeg);
                            break;
                    }
                    gr.Dispose();
                    bt.Dispose();
                    image.Dispose();
                }
                catch { }

            }

  • 相关阅读:
    10个好用的 HTML5 特性
    数字营销2.0时代已到来
    云原生时代,.NET5必将称王!
    为什么需要堡垒机
    从SOA和微服务到云原生解决方案实践
    阿里云资深技术专家李克畅谈边缘云计算趋势与实践
    OpenKruise v0.9.0 版本发布:新增 Pod 重启、删除防护等重磅功能
    浅谈分布式一致性:Raft 与 SOFAJRaft
    数仓架构的持续演进与发展 — 云原生、湖仓一体、离线实时一体、SaaS模式
    如何基于MaxCompute快速打通数据仓库和数据湖的湖仓一体实践
  • 原文地址:https://www.cnblogs.com/bestsaler/p/1835493.html
Copyright © 2011-2022 走看看