另一种方法是通过两次不同的方式混合您的图像。第一次通过,您只需在黑色矩形上添加多个辐射点,来自 White-Green-Transparency。
然后,在同一点,您从第 1 步中挖掘出您的第一张图像,并进行了 XOR 混合。
结果:
http://img11.imageshack.us/img11/7066/step3yr.png
编码:
public void creerLightMap(){
lightMap = new BufferedImage(this.getWidth(), this.getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D g = lightMap.createGraphics();
g.setColor(Color.BLACK);
g.fillRect(0, 0, this.getWidth(), this.getHeight());
float radius = 100;
//create color circle
for(int i=0; i<lumiere.size(); i++){
Point2D center = lumiere.get(i);
float[] dist = {0.0f, 0.5f, 1.0f};
Color[] colors = {new Color( 1.0f , 1.0f , 1.0f , 1.0f), new Color( 0.0f , 1.0f , 0.0f , 0.5f) , new Color( 0.0f , 1.0f , 0.0f , 0.0f)};
RadialGradientPaint p = new RadialGradientPaint(center, radius, dist, colors);
g.setPaint(p);
g.fillRect(0, 0, this.getWidth(), this.getHeight());
}
//add an alpha into theses same circle
for(int i=0; i<lumiere.size(); i++){
Point2D center = lumiere.get(i);
float[] dist = {0.0f, 1.0f};
Color[] colors = {new Color( 1.0f , 1.0f , 1.0f , 1.0f) , new Color( 1.0f , 1.0f , 1.0f , 0.0f)};
RadialGradientPaint p = new RadialGradientPaint(center, radius, dist, colors);
g.setComposite(AlphaComposite.getInstance(AlphaComposite.XOR, 1.0f));
g.setPaint(p);
g.fillRect(0, 0, this.getWidth(), this.getHeight());
}
g.dispose();
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D)g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2d.drawImage(this.lightMap, 0, 0, null);
}