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

        }

posted on 2010-07-07 15:01 sanmao 阅读(130) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航:
 

常用链接

留言簿(5)

随笔分类

随笔档案

搜索

  •  

最新评论

阅读排行榜

评论排行榜