如何压缩图像大小 [英] how to compress image size
本文介绍了如何压缩图像大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的客户希望图像应该是(380 * 380)分辨率我通过下面给出的代码完成了这个...现在大小应该是50-150 kb ...我怎么能压缩图像b / w 50- 150kb
my client wants the image should be (380*380) resolution i have done this through the below given code...Now size should be 50-150 kb... how i can compress the image b/w 50-150kb
private Bitmap Resize_Image(Stream streamImage, int maxWidth, int maxHeight)
{
Bitmap originalImage = new Bitmap(streamImage);
int newWidth = originalImage.Width;
int newHeight = originalImage.Height;
if (originalImage.Width > maxWidth)
{
newWidth = maxWidth;
}
if (originalImage.Height > maxHeight)
{
newHeight = maxHeight;
}
return new Bitmap(originalImage, newWidth, newHeight);
}
protected void btnUpload_Click(object sender, EventArgs e)
{
if (imgUpload.HasFile)
{
//string img = string.Empty;
Bitmap bmpImg = null;
try
{
//int fileSize = imgUpload.PostedFile.ContentLength;
// int maxFileSize = 150;
// if (maxFileSize > fileSize)
// {
// maxFileSize = fileSize;
// }
// else
// {
// maxFileSize = fileSize;
// }
bmpImg = Resize_Image(imgUpload.PostedFile.InputStream, 380, 380);
string fileName = imgUpload.PostedFile.FileName;
string saveLocation = Server.MapPath("UploadImages/" + fileName);
bmpImg.Save(saveLocation);
}
catch (Exception ex)
{
Response.Write("Error occured: " + ex.Message.ToString());
}
finally
{
img = string.Empty;
bmpImg.Dispose();
}
}
}
推荐答案
嗨...
你能看到这个吗,可能它的帮助已经全部给你了!
http://savotdane.blogspot.in/2009/08/how-to-compress-resize-image-in-net-c.html [ ^ ]
http://www.aspdotnet-suresh.com/2011/05/how-to-resize-size-image-without-losing.html [ ^ ]
如何减少asp中的图像大小。网络具有相同的清晰度 [ ^ ]
谢谢你。
Hi...
Can u see this one, may its help full to u!
http://savotdane.blogspot.in/2009/08/how-to-compress-resize-image-in-net-c.html[^]
http://www.aspdotnet-suresh.com/2011/05/how-to-resize-size-image-without-losing.html[^]
How to reduce image size in asp.net with same clarity[^]
Thank u.
这篇关于如何压缩图像大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文