日期:2014-05-17  浏览次数:20504 次

求一图片大小范围的计算
有一300*300的画布,
上传后的图片进行等比压缩,压缩后的宽度最小是300,压缩后的高度最小是200。原图片限定的大小是小于等于1M的,那么原图的原始图片长宽应该符合什么条件呢;当然这里面有个分辨率的不同,暂以72/(像素/英寸)来考虑,拜谢了

------解决方案--------------------
/// <summary>
/// </summary>
/// <param name="outCeshiPath">要压缩的图片的路径</param>
/// <param name="converPhoto">压缩后保存路径</param>
/// <remarks>
/// </remarks>
public static void CompressMinImage(string pPath, string outCeshiPath, string converPhoto)
{
int width = 300;
int height = 200;
Image img = Image.FromFile(outCeshiPath);
int W = img.Width - width;
int H = img.Height - height;
if (img.Width >= 300&& img.Height >= 200)
{
Image originalImg = Image.FromFile(outCeshiPath);
Bitmap bmpOut = new Bitmap(width, height, PixelFormat.Format24bppRgb);
Graphics g = Graphics.FromImage(bmpOut);
g.DrawImage(originalImg, new Rectangle(0, 0, width, height), new Rectangle(0, 0, width, height), GraphicsUnit.Pixel);
bmpOut.Save(converPhoto, ImageFormat.Jpeg);
originalImg.Dispose();
bmpOut.Dispose();
g.Dispose();
}else{
//xxxxxxxxxx
}

}