Open GoogleCodeExporter opened 8 years ago
Original comment by m%nobel-...@gtempaccount.com
on 5 Feb 2011 at 1:42
+1 it would be nice to create square with black border if the the original
image is not a square.
The following code works great for me :
ResampleOp resampleOp = new ResampleOp( destWidth, destHeight );
resampleOp.setUnsharpenMask( AdvancedResizeOp.UnsharpenMask.Normal );
BufferedImage destImage = resampleOp.filter( sourceImage, null );
ImageIO.write( destImage, "JPG", "rescaled.jpg" );
//Generate square image
BufferedImage resImage = ImageIO.read( "rescaled.jpg" );
BufferedImage resultImage =
new BufferedImage( imageSize.longSide, imageSize.longSide, BufferedImage.TYPE_INT_RGB );
Graphics2D resultGraphics = resultImage.createGraphics();
double translateX = ( imageSize.longSide - destWidth ) / 2;
double translateY = ( imageSize.longSide - destHeight ) / 2;
AffineTransform resultAffineTransform = AffineTransform.getTranslateInstance( translateX, translateY );
resultGraphics.drawRenderedImage( resImage, resultAffineTransform );
ImageIO.write( resultImage, "PNG", "square.png" );
resultGraphics.dispose();
Original comment by thomas.bruyelle@gmail.com
on 3 Apr 2012 at 8:30
Original issue reported on code.google.com by
sebastia...@gmail.com
on 12 Jan 2011 at 8:57