开发者

Portrait image resizing in java with imgscalr, but the final output is landscape. How to guarantee it stays the same orientation?

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, Scal开发者_如何学Gor.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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜