在java中使用imgscalr调整肖像图像大小,但最终输出是风景。如何保证其保持同一方向?

发布于 2024-11-26 16:19:56 字数 748 浏览 4 评论 0原文

我正在使用 imgscalr 在 Grails 应用程序中创建缩放图像。这是代码:

BufferedImage sourceImg = ImageIO.read(new File("/tmp" + File.separator + filename))
BufferedImage destImg = null

if(sourceImg.height >= sourceImg.width){
    destImg = Scalr.resize(sourceImg, Scalr.Method.AUTOMATIC, Scalr.Mode.FIT_TO_HEIGHT, 800) 
}
else{
    destImg = Scalr.resize(sourceImg, Scalr.Method.AUTOMATIC, Scalr.Mode.FIT_TO_WIDTH, 800)
}

File newFile = new File("/tmp/processed" + File.separator + filename)
String formatName = foto.nomeArquivo.substring(foto.nomeArquivo.lastIndexOf('.')+1);
ImageIO.write(imgDestino, formatName.toUpperCase(), newFile)

到目前为止,请不要介意 formatName...我仍在测试 imgscalr 库。

我所有的图像都以横向结束。我正在 Mac 操作系统中进行开发。

谢谢

I am using imgscalr to create scale my images in a Grails application. Here is the code:

BufferedImage sourceImg = ImageIO.read(new File("/tmp" + File.separator + filename))
BufferedImage destImg = null

if(sourceImg.height >= sourceImg.width){
    destImg = Scalr.resize(sourceImg, Scalr.Method.AUTOMATIC, Scalr.Mode.FIT_TO_HEIGHT, 800) 
}
else{
    destImg = Scalr.resize(sourceImg, Scalr.Method.AUTOMATIC, Scalr.Mode.FIT_TO_WIDTH, 800)
}

File newFile = new File("/tmp/processed" + File.separator + filename)
String formatName = foto.nomeArquivo.substring(foto.nomeArquivo.lastIndexOf('.')+1);
ImageIO.write(imgDestino, formatName.toUpperCase(), newFile)

Please do not mind about formatName so far.... I am still testing the imgscalr library.

All my images end in landscape orientation. I am developing in a Mac OS.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文