在 asp.net 中调整图像大小而不损失图像质量
我正在开发一个 ASP.NET 3.5 Web 应用程序,其中允许我的用户上传 jpeg、gif、bmp 或 png 图像。如果上传的图像尺寸大于 103 x 32,我想将上传的图像大小调整为 103 x 32。我已经阅读了一些博客文章和文章,并且还尝试了一些代码示例,但似乎没有任何效果。有人成功做到这一点吗?
I am developing an ASP.NET 3.5 web application in which I am allowing my users to upload either jpeg,gif,bmp or png images. If the uploaded image dimensions are greater then 103 x 32 the I want to resize the uploaded image to 103 x 32. I have read some blog posts and articles, and have also tried some of the code samples but nothing seems to work right. Has anyone succeed in doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
这是我使用的代码。它支持旋转,并将图像分辨率设置为 72dpi@24 位颜色的 JPEG 标准(默认情况下 GDI+ 以 96dpi@32 位颜色保存图像)。它还修复了一些人在调整图像大小时遇到的黑/灰边框问题。
This is the code I use. It supports rotation, and also sets the image resolution to the JPEG standards of 72dpi@24-bit color (by default GDI+ saves images at 96dpi@32-bit color). It also fixes the black/gray border problem that some people experience when resizing images.
不久前我遇到了同样的问题,并以这种方式处理:
我刚刚读到这是获得最高质量的方法。
I had the same problem a while back and dealt with it this way:
I just read that this was the the way to get highest quality.
与位图实际调整大小相关的代码如下。
这篇博客文章包含用于图像调整大小和压缩(如果需要)的完整源代码
http://blog.bombdefused.com/2010/08/bulk-image-optimizer-in-c-full-source.html
The code associated with the actual resizing of the bitmap is as follows.
This blog post contains full source code for image resizing, and compression (if required)
http://blog.bombdefused.com/2010/08/bulk-image-optimizer-in-c-full-source.html
我已经通过创建图像的位图然后调整位图的大小成功地完成了此操作...我不确定这是否是最好或最有效的方法,但它对我有用。
就我而言,我需要将图像的高度和宽度削减一半。
这就是我所做的。
I've successfully done this by creating a bitmap of the image and then resizing the bitmap...I'm not sure if this is the best or most efficient way of doing this, but it works for me.
In my case, I needed to cut the height and width of the image by half.
Here's what I did.