Java操作应用——图片缩放
图片缩放可以通过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" )); } } |
点击加载更多评论>>