压缩图片

View Code
 private Byte[] YaSuo(Image img)
        {
            int height = 240;
            int width = img.Width * height / img.Height;

            Bitmap bmp = new Bitmap(width, height);
            Graphics grap = Graphics.FromImage(bmp);
            grap.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            grap.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            grap.DrawImage(img, new Rectangle(0, 0, width, height));

            MemoryStream mStream = new MemoryStream();
            bmp.Save(mStream, System.Drawing.Imaging.ImageFormat.Jpeg);
            Byte[] picByte = mStream.GetBuffer();

            bmp.Dispose();
            grap.Dispose();

            bmp = null;
            grap = null;


            mStream.Close();
            mStream.Dispose();
            mStream = null;


            return picByte;
        }

 

posted @ 2012-09-10 09:57  宋佳莉  阅读(180)  评论(0编辑  收藏  举报