Java Code Examples for java.awt.Image.SCALE_SMOOTH

The following are Jave code examples for showing how to use SCALE_SMOOTH of the java.awt.Image class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: springboot-training   File: ImageUtil.java   View Source Code Vote up 6 votes
private Image getResizedImage(Image image, int newSize, int operation) {
	int iWidth = image.getWidth(null);
	int iHeight = image.getHeight(null);
	int hints = Image.SCALE_SMOOTH;
	switch (operation) {
	case 1:// 按宽度缩放
		return image.getScaledInstance(newSize, (newSize * iHeight) / iWidth, hints);
	case 2:// 按高度缩放
		return image.getScaledInstance((newSize * iWidth) / iHeight, newSize, hints);
	default:// 哪边大按哪边缩放
		if (iWidth > iHeight) {
			return image.getScaledInstance(newSize, (newSize * iHeight) / iWidth, hints);
		} else {
			return image.getScaledInstance((newSize * iWidth) / iHeight, newSize, hints);
		}
	}
}
 
Example 2
Project: powertext   File: BufferedImageBackgroundPainterStrategy.java   View Source Code Vote up 5 votes
/**
 * Rescales the displayed image to be the specified size.
 *
 * @param width The new width of the image.
 * @param height The new height of the image.
 * @param hint The scaling hint to use.
 */
@Override
protected void rescaleImage(int width, int height, int hint) {

	Image master = getMasterImage();
	if (master!=null) {

		Map<RenderingHints.Key, Object> hints =
				new HashMap<RenderingHints.Key, Object>();
		switch (hint) {
			default:
			case Image.SCALE_AREA_AVERAGING:
			case Image.SCALE_SMOOTH:
				hints.put(RenderingHints.KEY_INTERPOLATION,
						RenderingHints.VALUE_INTERPOLATION_BICUBIC);
				hints.put(RenderingHints.KEY_RENDERING,
						RenderingHints.VALUE_RENDER_QUALITY);
				hints.put(RenderingHints.KEY_ANTIALIASING,
						RenderingHints.VALUE_ANTIALIAS_ON);
		}

		bgImage = createAcceleratedImage(width, height);
		Graphics2D g = bgImage.createGraphics();
		g.addRenderingHints(hints);
		g.drawImage(master, 0,0, width,height, null);
		g.dispose();

	}
	else {
		bgImage = null;
	}
}