Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

BufferedImage mit Transparenz als Schablone

Empfohlene Antworten

Veröffentlicht

Hi,

ich hatte eigentlich vor ein Buffered Image mit Transparenz als Schablone für ein anderes Image zu verwenden.

Zuerst lege ich mir ein Image an welches Transparenz unterstützt, danach setzte ich die Hintergrundfarbe halbtransparent und cleare das Image.


BufferedImage flightZonesImage = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().createCompatibleImage(getWidth(), getHeight(), Transparency.TRANSLUCENT);

graph.setBackground(new Color(0,0,0,100));

graph.clearRect(0, 0, getWidth(), getHeight());

Das funktiert auch soweit ganz gut. Jetzt setzte ich die Farbe auf 100% Transparent und zeichne ein Polygon.

graph.setColor(new Color(0,0,0,0));

graph.fillPolygon(xPoints, yPoints, xPoints.length);

Und genau da liegt das Problem. Java setzt jetzt nicht die Pixel da wo das Polygone ist auf Transparent, sondern manipuliert sie scheinbar mit der Color(0,0,0) zu 0%. Wenn ich die 4. Ziffer nämlich auf 100 setze ist die Transparenz an der stelle nämlich in etwa halb so stark wie an den anderen stellen des Images.

Hat jemand eine Idee wie man dennoch bestimmte Stellen in einem Image im nachhinein zu 100% transparent bekommt? clearRect(...) nützt mir nichts, da ich komplexer Formen brauche als nur Rechtecke.

ich vermute es wird so etwas wie setXY/setColorAt geben.

  • Autor
ich vermute es wird so etwas wie setXY/setColorAt geben.

Zum einen würde es mir bei meinem Problem nicht helfen und zum anderen ist mir so etwas sowohl bei BufferedImage als auch bei Graphics2D nicht bekannt.

Helfen würde es nichts, da ich hauptsächlich transparente Polygone brauche die auch komplexere Formen haben können. Wenn ich da anfange mir erstmal auszurechnen welche Bildpunkte betroffen sind und dann fleißig einzelne Farbwerte setzte kann ich bei einer Bildfrequenz von 10Hz noch paar Jahre warten bis es solche Rechner gibt wo das läuft.

Hab aber gestern Abend dann doch noch die Lösung gefunden. Ich weiß zwar nicht so ganz wieso aber nachdem ich diese Zeile ausführe...

graphics.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, 0));

...machen sämtliche draw- oder fill-methoden genau das was ich will. Nämlich die gerade gesetzte Farbe an den betroffenen Stellen als Imagefarbe zu setzen und sie nicht mit dem Image an den Stellen abzugleichen.

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.