解决Java处理png图片时透明背景变黑的问题

解决Java处理png图片时透明背景变黑的问题

// Copy image to buffered image
Graphics2D g = bimage.createGraphics();

// 下面两行解决png透明图片会变黑的问题
bimage = g.getDeviceConfiguration().createCompatibleImage(image.getWidth(null), image.getHeight(null), Transparency.TRANSLUCENT);
g = bimage.createGraphics();

// Paint the image onto the buffered image
g.drawImage(image, 0, 0, null);

你可能感兴趣的:(java)