private Image getOpacityImage(Image image, double opacity) {
PixelReader pixelReader = image.getPixelReader();
WritableImage wImage = new WritableImage((int) image.getWidth(), (int) image.getHeight());
PixelWriter pixelWriter = wImage.getPixelWriter();
for (int readY = 0; readY < image.getHeight(); readY++) {
for (int readX = 0; readX < image.getWidth(); readX++) {
Color color = pixelReader.getColor(readX, readY);
// png格式图片透明部分保持透明
if(color.getOpacity() != 0){
Color c1 = new Color(color.getRed(), color.getGreen(), color.getBlue(), opacity);
pixelWriter.setColor(readX, readY, c1.brighter());
}
}
}
return wImage;
}