上载到服务器后减小图像大小 [英] Reduce image size after upload to server
本文介绍了上载到服务器后减小图像大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
只需阅读有关调整图像大小的一些文章,但在用户从数字电话摄像头上传图像后找不到能减小尺寸的文章?
我正在寻找的是一种在用户上载到Web服务器后立即进行大小调整的工具?谁能指出一个方向?
rgds,
kfl.
Hi,
Just read some articless on resize image but can not find one that can do reduce the size after the user upload a image from digital phone camera?
What I am looking for is a facility to do the resize on the fly - immediately after user upload to the web server? Can anyone point a direction?
rgds,
kfl.
推荐答案
KF!
我只是从 http://www.switchedonthecode.com :
Hi KF!
I just scratched this from http://www.switchedonthecode.com:
private static Image resizeImage(Image imgToResize, Size size)
{
int sourceWidth = imgToResize.Width;
int sourceHeight = imgToResize.Height;
float nPercent = 0;
float nPercentW = 0;
float nPercentH = 0;
nPercentW = ((float)size.Width / (float)sourceWidth);
nPercentH = ((float)size.Height / (float)sourceHeight);
if (nPercentH < nPercentW)
nPercent = nPercentH;
else
nPercent = nPercentW;
int destWidth = (int)(sourceWidth * nPercent);
int destHeight = (int)(sourceHeight * nPercent);
Bitmap b = new Bitmap(destWidth, destHeight);
Graphics g = Graphics.FromImage((Image)b);
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.DrawImage(imgToResize, 0, 0, destWidth, destHeight);
g.Dispose();
return (Image)b;
}
我当然希望您的意思是ASP.net,而不是ASP. ASP已死,应该早就被埋葬了:).
不过,希望该代码段对您有所帮助!
干杯,
曼弗雷德(Manfred)
I sure do hope you meant ASP.net and not ASP. ASP is dead and should have been buried a long time ago :) .
Nevertheless, I hope the code snippet helps you!
Cheers,
Manfred
这篇关于上载到服务器后减小图像大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文