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 { }

            }

  • 相关阅读:
    spymemcache与spring结合
    Turtle库的学习积累
    汉诺塔绘图学习
    计算圆周率π和显示进度条
    川菜 in English
    一些必不可少的Sublime Text 2插件 钟磊的专栏 博客频道 CSDN.NET
    \usepackage{natbib}在latex模板写作中的心得_格致轩_百度空间
    Geant4新版本:新安装方法,新运行方式
    ubuntu系统备份
    Latex数学公式中的空格
  • 原文地址:https://www.cnblogs.com/bestsaler/p/1835493.html
Copyright © 2011-2022 走看看