Ist dies mit den Standard-JRE-Systembibliotheken möglich?
Ja, es ist möglich und ist auch ziemlich einfach. Der folgende Code erzeugt dieses Bild (transparent png):
public static void main(String[] args) throws IOException {
int x = 50, y = 50, w = 300, h = 200;
// draw the "shadow"
BufferedImage img = new BufferedImage(400, 300, BufferedImage.TYPE_INT_ARGB);
Graphics g = img.getGraphics();
g.setColor(Color.BLACK);
g.fillRect(x + 10, y + 10, w, h);
// blur the shadow
BufferedImageOp op = getBlurredOp();
img = op.filter(img, null);
// draw the box
g = img.getGraphics();
g.setColor(Color.RED);
g.fillRect(x, y, w, h);
// write it to disk
ImageIO.write(img, "png", new File("test.png"));
}
private static BufferedImageOp getBlurredOp() {
float[] matrix = new float[400];
for (int i = 0; i < 400; i++)
matrix[i] = 1.0f/400.0f;
return new ConvolveOp(new Kernel(20, 20, matrix),
ConvolveOp.EDGE_NO_OP, null);
}
, die diese Art von Bedienung einfach machen Bibliotheken würden?
Ich würde sagen, dass es auf Ihre anderen Anwendungsfälle abhängt. Für einfache Formen wie Boxen und Ovale würde ich für die obige Lösung gehen, keine Bibliothek wird benötigt.
[Arbeiten mit Bildern] (http://docs.oracle.com/javase/tutorial/2d/images/index.html) – Jeffrey
Hier ist eine Frage zu Alphamasken in Java http://StackOverflow.com/Questions/ 221830/set-bufferedimage-alpha-maske-in-java – Patrick
danke Jeffry Ich bin dabei ... – pstanton