在 ASP.NET 项目中调整用户上传图像的大小 – 图书馆?
在一个相当简单的 ASP.NET 应用程序中,用户可以上传图像,大部分来自他的数码相机。 我必须将其大小调整为适合网络和缩略图的可用大小。 这里的最佳实践是什么? 有没有一个库可以让我以简单的方式实现,而无需在网络服务器上安装某些东西。
In a rather simple ASP.NET application where the user can upload a image, mostly from his digital camera. I have to resize it to a workable size for the web and a thumbnail.
What is here the best practice for? Is there a library that I in a simple way can implement without installing something on the web server.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
SO 上的这个线程可能会帮助您决定:
什么是最好的图像处理库< /a>
This thread on SO will probably help you decide:
What is the best image manipulation library
免责声明:我是这个库的作者。
然而,它正是为此目的而设计的,并且非常成熟且经过充分测试。
http://nathanaeljones.com/products/asp-net-image-resizer/
我认为您会发现包含的示例应用程序正是您所需要的。
Disclaimer: I am the author of this library.
However, it was designed exactly for this purpose, and is very mature and well-tested.
http://nathanaeljones.com/products/asp-net-image-resizer/
I think you will find the included sample application does exactly what you need.
看看 BitMap 类 - 你通过在构造函数中指定大小可以很容易地做到这一点。
因此,想象一下您想要将其减半:
如果您想要更高质量的解决方案,您需要 考虑 InterpolationMode 枚举。
对于您描述的简单场景,您当然不需要费心使用第三方库。
Look at the BitMap class- you can do this quite easily by specifying the size in the constructor.
So imagine you wanted to half it:
If you want a higher quality solution, you need to consider the InterpolationMode enumeration.
For the simple scenario you describe you certainly don't need to bother with 3rd party libraries.
我不是图像专家,但我在网站上实现了图像大小调整并使用了如下内容:
I am no image expert, but I implemented image resizing on a website and used something like this:
使用 Bitmap(以及任何其他 System.Drawing 类)是 在 ASP.NET 中特别禁止(请参阅文档页面顶部附近的警告)。
使用它们可能会导致如下异常:
并且
根据您尝试执行的操作,Windows 成像组件 可能会满足您的需求。 我们还很幸运地创建了一个 STA 线程并调用所有绘图操作。
Using Bitmap (and any other System.Drawing classes) is specifically prohibited in ASP.NET (see the warning near the top of the documentation page).
Using them may result in exceptions such as these:
and
Depending on what you are trying to do, Windows Imaging Component may fill your need. We have also had luck by creating a single STA thread and invoking all drawing operations over to that.