1.图像在存储前就要压缩,jpg本来就是压缩后的格式,所只把图像存为jpg
if(IsProportion)
{
//图像按比较缩放
if(imgWidth>imgHeight)
{
//图像形装是横长方形
picWidth=width; //此处设置图片宽度参数
picHeight=(imgHeight/imgWidth)*picWidth; //按比例缩放图片
}// end if
else if(imgWidth.Equals(imgHeight))
{
//图像形状是正方形
picWidth=width; //按指定的宽度缩放图片
picHeight=height; //按指定的高度缩放图片
}// end else if
else
{
//图像形状是竖长方形
picHeight=width; //此处设置图片高度参数
picWidth=(imgWidth/imgHeight)*picHeight; //按比例缩放图片
}// end else
}// end if
else
{
//图像按指定的尺寸缩放
picWidth=width; //按指定的宽度缩放图片
picHeight=height; //按指定的高度缩放图片
}// end else
//以新图像大小创建一块画布
using( System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap( (int)picWidth ,(int)picHeight, PixelFormat.Format32bppArgb)) //using 3
{
using( System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage( bitmap ) ) //using 4
{
//清除整个绘图面并以透明背景色填充
graphics.Clear( Color.Transparent );
//在指定位置并且按指定大小绘制 原图片 对象
graphics.DrawImage(img, new Rectangle(0, 0,(int)picWidth, (int)picHeight));
bitmap.Save(Stream2,System.Drawing.Imaging.ImageFormat.Jpeg);
if(IsProportion)
{
//图像按比较缩放
if(imgWidth>imgHeight)
{
//图像形装是横长方形
picWidth=width; //此处设置图片宽度参数
picHeight=(imgHeight/imgWidth)*picWidth; //按比例缩放图片
}// end if
else if(imgWidth.Equals(imgHeight))
{
//图像形状是正方形
picWidth=width; //按指定的宽度缩放图片
picHeight=height; //按指定的高度缩放图片
}// end else if
else
{
//图像形状是竖长方形
picHeight=width; //此处设置图片高度参数
picWidth=(imgWidth/imgHeight)*picHeight; //按比例缩放图片
}// end else
}// end if
else
{
//图像按指定的尺寸缩放
picWidth=width; //按指定的宽度缩放图片
picHeight=height; //按指定的高度缩放图片
}// end else
//以新图像大小创建一块画布
using( System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap( (int)picWidth ,(int)picHeight, PixelFormat.Format32bppArgb)) //using 3
{
using( System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage( bitmap ) ) //using 4
{
//清除整个绘图面并以透明背景色填充
graphics.Clear( Color.Transparent );
//在指定位置并且按指定大小绘制 原图片 对象
graphics.DrawImage(img, new Rectangle(0, 0,(int)picWidth, (int)picHeight));
bitmap.Save(Stream2,System.Drawing.Imaging.ImageFormat.Jpeg);