方式一
从网上搜索出来的方案
BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);Graphics2D graphics = bufferedImage.createGraphics();bufferedImage = graphics.getDeviceConfiguration().createCompatibleImage(width, height, Transparency.TRANSLUCENT);复制代码
方式二
稍微精简
BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);BufferedImageGraphicsConfig config = BufferedImageGraphicsConfig.getConfig(bufferedImage);bufferedImage =config.createCompatibleImage(width, height, Transparency.TRANSLUCENT);复制代码
方式三
最底层代码
ColorModel cm = ColorModel.getRGBdefault();WritableRaster wr = cm.createCompatibleWritableRaster(width, height);BufferedImage bufferedImage = new BufferedImage(cm, wr, cm.isAlphaPremultiplied(), null);复制代码