使用java进行服务器端图像重采样的库?
我想使用 jsp 创建一个重新采样(缩小)的图像版本。 原始图像作为 blob 存储在数据库中。 我想创建一个 jsp,根据传递的图像宽度/高度(例如 getimage.jsp?imageid=xxxx&maxside=200) 提供具有良好质量(不是像素化)的下采样图像。 你能给我指一个可以从 jsp 页面调用的开源 api 或代码吗?
I want to create a serve resampled (downsized) version of images using jsp. The original images are stored in the database as blobs. I want to to create a jsp that serves a downsampled image with decent quality (not pixelated) as per the passed image width/height (e.g. getimage.jsp?imageid=xxxx&maxside=200) . Can you point me to a opensource api or code that I can call from the jsp page?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Java 已经包含用于图像处理的库。 调整图像大小并从 JSP 输出应该很容易。
这个 servlet 看起来和你做的事情非常相似想让你的JSP做什么。
Java already contains libraries for image manipulation. It should be easy to resize an image and output it from a JSP.
This servlet looks like it does a very similar thing to what you want your JSP to do.
内置的 Image.getScaledInstance(w, h,hins) 有什么问题吗? (*)
使用hints=Image.SCALE_SMOOTH 获得不那么糟糕的缩略图。 然后使用ImageIO转换为输出所需的格式。
*:是的,它有问题,有点慢,但实际上,考虑到所有其他网络开销,这不太可能是一个大问题。 当放大图像时,它也不是最好的质量,具有 BICUBIC 渲染提示的 drawImage 更合适。 但你目前只是在谈论缩小规模。
请务必检查传入的大小,以便您无法通过传入巨大的大小来拒绝服务您的 servlet,从而导致创建占用大量内存的图像。
Is there anything wrong with the built-in Image.getScaledInstance(w, h, hints)? (*)
Use hints=Image.SCALE_SMOOTH to get non-horrible thumbnailing. Then use an ImageIO to convert to the required format for output.
*: well yes, there is something wrong with it, it's a bit slow, but really with all the other web overhead to worry about that's not likely to be much of an issue. It's also not the best quality for when upscaling images, where a drawImage with BICUBIC renderinghint is more suitable. But you're talking about downscaling only at the moment.
Be sure to check the sizes passed in so that you can't DoS your servlet by passing in enormous sizes causing a memory-eatingly-huge image to be created.