我一直致力于Java 2D游戏,我注意到我的屏幕和精灵太小了。用手放大它们会很痛苦。
使用Java 2D将图像绘制到面板时,是否可以放大JFrame或JPanel及其所有内容?
答案 0 :(得分:1)
Graphics2D提供如下图像重新调整大小的功能:
BufferedImage resizedImage = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, type);
Graphics2D g = resizedImage.createGraphics();
g.drawImage(originalImage, 0, 0, IMG_WIDTH, IMG_HEIGHT, null);
g.dispose();
根据一些文章,如果您想增加重新调整大小的图像质量,可以按如下方式添加RenderingHints:
BufferedImage resizedImage = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, type);
Graphics2D g = resizedImage.createGraphics();
g.drawImage(originalImage, 0, 0, IMG_WIDTH, IMG_HEIGHT, null);
g.dispose();
g.setComposite(AlphaComposite.Src);
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g.setRenderingHint(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
来源:http://www.mkyong.com/java/how-to-resize-an-image-in-java/
值得一试的其他链接:
http://www.javaprogrammingforums.com/algorithms-recursion/818-change-size-image.html