图片缩放的Java类
2018-07-20 来源:open-open
import java.awt.Graphics2D; import java.awt.Image; import java.awt.image.BufferedImage; import java.awt.image.ColorModel; import com.jhlabs.image.AbstractBufferedImageOp; /** * Scales an image using the area-averaging algorithm, which can't be done with AffineTransformOp. */ public class MyScaleFilter extends AbstractBufferedImageOp { private int width; private int height; /** * Construct a ScaleFilter. */ public MyScaleFilter() { this(32, 32); } /** * Construct a ScaleFilter. * @param width the width to scale to * @param height the height to scale to */ public MyScaleFilter( int width, int height ) { this.width = width; this.height = height; } public BufferedImage filter( BufferedImage src, BufferedImage dst ) { if ( dst == null ) { ColorModel dstCM = src.getColorModel(); dst = new BufferedImage(dstCM, dstCM.createCompatibleWritableRaster( width, height ), dstCM.isAlphaPremultiplied(), null); } Image scaleImage = src.getScaledInstance( width, height, Image.SCALE_SMOOTH ); Graphics2D g = dst.createGraphics(); g.drawImage( scaleImage, 0, 0, width, height, null ); g.dispose(); return dst; } public String toString() { return "Distort/Scale"; } }
标签: isp
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
上一篇:java实现截屏程序
最新资讯
热门推荐