Java操作應(yīng)用——圖片縮放
圖片縮放可以通過AffineTransform來完成。首先要生成一個輸入圖片的圖片緩沖,然后通過它來渲染出縮放后的圖片。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | import java.awt.Graphics2D; import java.awt.geom.AffineTransform; import java.awt.image.BufferedImage; import java.io.File; import javax.imageio.ImageIO; public class RescaleImage { public static void main(String[] args) throws Exception { BufferedImage imgSource = ImageIO.read( new File( "images//Image3.jpg" )); BufferedImage imgDestination = new BufferedImage( 100 , 100 , BufferedImage.TYPE_INT_RGB); Graphics2D g = imgDestination.createGraphics(); AffineTransform affinetransformation = AffineTransform.getScaleInstance( 2 , 2 ); g.drawRenderedImage(imgSource, affinetransformation); ImageIO.write(imgDestination, "JPG" , new File( "outImage.jpg" )); } } |
點擊加載更多評論>>