#region SaveSmallPhoto /// <summary> /// 高清晰缩略图算法 /// </summary> /// <param name="postFile">图片文件对象</param> /// <param name="saveImg">要保存为缩略图的源文件</param> /// <param name="Width">宽度</param> /// <param name="Height">高度</param> public void MakeSmallImg(System.Web.HttpPostedFile postFile, string saveImg, System.Double Width, System.Double Height) { //SourcePhotoName string m_OriginalFilename = postFile.FileName; string m_strGoodFile = saveImg; //GetPhotoObject From SourceFile System.Drawing.Image m_Image = System.Drawing.Image.FromStream(postFile.InputStream, true); System.Double NewWidth, NewHeight; if (m_Image.Width > m_Image.Height) { NewWidth = Width; NewHeight = m_Image.Height * (NewWidth / m_Image.Width); } else { NewHeight = Height; NewWidth = (NewHeight / m_Image.Height) * m_Image.Width; } if (NewWidth > Width) { NewWidth = Width; } if (NewHeight > Height) { NewHeight = Height; } //GetPhotoSize System.Drawing.Size size =new System.Drawing.Size((int)NewWidth, (int)NewHeight); //The New of Bimp Photo System.Drawing.Image bitmap = new System.Drawing.Bitmap(size.Width, size.Height); // The New of Palette System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap); // Set HightQuality Arithmetic For Graphics g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; //设置高质量,低速度呈现平滑程度 g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; //ClearCanvas g.Clear(System.Drawing.Color.White); //在指定位置画图 g.DrawImage(m_Image, new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), new System.Drawing.Rectangle(0, 0, m_Image.Width, m_Image.Height), System.Drawing.GraphicsUnit.Pixel); |