import java.awt.image.BufferedImage; import java.awt.Graphics2D; import java.awt.Color;
public static BufferedImage canvas(BufferedImage source, int width, int height, int x, int y, int cx, int cy, Color color){ BufferedImage out = new BufferedImage(width, height, source.getType()); Graphics2D g2d = out.createGraphics(); g2d.setColor(color); g2d.fillRect(0, 0, width, height); g2d.drawImage(source, x - cx, y - cy, source.getWidth(), source.getHeight(), null); g2d.dispose(); return out; } public static BufferedImage canvas(BufferedImage source, int width, int height){ return canvas(source, width, height, width / 2, height / 2, source.getWidth() / 2, source.getHeight() / 2, Color.WHITE); }
修改前
before

以 canvas(source, 200, 200) 修改後
edit with canvas(source, 200, 200)

以 canvas(source, 400, 400) 修改後
edit with canvas(source, 400, 400)

以 canvas(source, 400, 400, 0, 0, 0, 0, Color.RED) 修改後
edit with canvas(source, 400, 400, 0, 0, 0, 0, Color.RED)

沒有留言 :
張貼留言