Search in sources :

Example 31 with AlphaComposite

use of java.awt.AlphaComposite in project litiengine by gurkenlabs.

the class OrthogonalMapRenderer method renderImageLayer.

private void renderImageLayer(Graphics2D g, IImageLayer layer, Rectangle2D viewport) {
    final Composite oldComp = g.getComposite();
    final AlphaComposite ac = java.awt.AlphaComposite.getInstance(AlphaComposite.SRC_OVER, layer.getOpacity());
    g.setComposite(ac);
    final double viewportOffsetX = -viewport.getX() + layer.getPosition().x;
    final double viewportOffsetY = -viewport.getY() + layer.getPosition().y;
    Spritesheet sprite = Spritesheet.find(layer.getImage().getSource());
    if (sprite == null) {
        return;
    }
    RenderEngine.renderImage(g, sprite.getImage(), viewportOffsetX, viewportOffsetY);
    g.setComposite(oldComp);
}
Also used : Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) AlphaComposite(java.awt.AlphaComposite) Spritesheet(de.gurkenlabs.litiengine.graphics.Spritesheet)

Example 32 with AlphaComposite

use of java.awt.AlphaComposite in project jdk8u_jdk by JetBrains.

the class SunGraphics2D method validateColor.

/*
     * Validate the eargb and pixel fields against the current color.
     *
     * The eargb field must take into account the extraAlpha
     * value of an AlphaComposite.  It may also take into account
     * the Fsrc Porter-Duff blending function if such a function is
     * a constant (see handling of Clear mode below).  For instance,
     * by factoring in the (Fsrc == 0) state of the Clear mode we can
     * use a SrcNoEa loop just as easily as a general Alpha loop
     * since the math will be the same in both cases.
     *
     * The pixel field will always be the best pixel data choice for
     * the final result of all calculations applied to the eargb field.
     *
     * Note that this method is only necessary under the following
     * conditions:
     *     (paintState <= PAINT_ALPHA_COLOR &&
     *      compositeState <= COMP_CUSTOM)
     * though nothing bad will happen if it is run in other states.
     */
final void validateColor() {
    int eargb;
    if (imageComp == CompositeType.Clear) {
        eargb = 0;
    } else {
        eargb = foregroundColor.getRGB();
        if (compositeState <= COMP_ALPHA && imageComp != CompositeType.SrcNoEa && imageComp != CompositeType.SrcOverNoEa) {
            AlphaComposite alphacomp = (AlphaComposite) composite;
            int a = Math.round(alphacomp.getAlpha() * (eargb >>> 24));
            eargb = (eargb & 0x00ffffff) | (a << 24);
        }
    }
    this.eargb = eargb;
    this.pixel = surfaceData.pixelFor(eargb);
}
Also used : AlphaComposite(java.awt.AlphaComposite) RadialGradientPaint(java.awt.RadialGradientPaint) Paint(java.awt.Paint) TexturePaint(java.awt.TexturePaint) LinearGradientPaint(java.awt.LinearGradientPaint) GradientPaint(java.awt.GradientPaint)

Example 33 with AlphaComposite

use of java.awt.AlphaComposite in project pentaho-kettle by pentaho.

the class SwingGC method setAlpha.

public void setAlpha(int alpha) {
    this.alpha = alpha;
    AlphaComposite alphaComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha / 255);
    gc.setComposite(alphaComposite);
}
Also used : AlphaComposite(java.awt.AlphaComposite)

Example 34 with AlphaComposite

use of java.awt.AlphaComposite in project cytoscape-impl by cytoscape.

the class ImageAnnotationImpl method paint.

@Override
public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    if (image == null)
        return;
    // Get the stroke
    int border = (int) Math.round(getBorderWidth() * getZoom());
    // Calculate the new width & height
    int width = getWidth() - border;
    int height = getHeight() - border;
    if (resizedImage == null || resizedImage.getWidth() != width || resizedImage.getHeight() != height)
        resizedImage = resizeImage(width, height);
    int x = 0;
    int y = 0;
    AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity);
    g2.setComposite(ac);
    g2.drawImage(resizedImage, x + border + 1, y + border + 1, this);
    super.paint(g);
}
Also used : AlphaComposite(java.awt.AlphaComposite) Paint(java.awt.Paint) Graphics2D(java.awt.Graphics2D)

Example 35 with AlphaComposite

use of java.awt.AlphaComposite in project cytoscape-impl by cytoscape.

the class ImageAnnotationImpl method drawAnnotation.

@Override
public void drawAnnotation(Graphics g, double x, double y, double scaleFactor) {
    super.drawAnnotation(g, x, y, scaleFactor);
    Graphics2D g2 = (Graphics2D) g;
    // Get the stroke
    int border = (int) Math.round(getBorderWidth() * scaleFactor);
    int width = (int) Math.round(shapeWidth * scaleFactor / getZoom()) - border * 2 + 1;
    int height = (int) Math.round(shapeHeight * scaleFactor / getZoom()) - border * 2 + 1;
    int xInt = (int) Math.round(x * scaleFactor) + border + 1;
    int yInt = (int) Math.round(y * scaleFactor) + border + 1;
    // System.out.println("ImageAnnotationImpl: drawAnnotation - width="+width+", height="+height+", border="+border);
    // System.out.println("ImageAnnotationImpl: drawAnnotation - x="+x+",y="+y+", xInt="+xInt+", yInt="+yInt);
    BufferedImage newImage = resizeImage(width, height);
    if (newImage == null)
        return;
    // boolean selected = isSelected();
    // setSelected(false);
    AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity);
    g2.setComposite(ac);
    g2.drawImage(newImage, xInt, yInt, null);
// GraphicsUtilities.drawShape(g, 0, 0,
// getWidth()-1, getHeight()-1, this, false);
// setSelected(selected);
}
Also used : AlphaComposite(java.awt.AlphaComposite) Paint(java.awt.Paint) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Aggregations

AlphaComposite (java.awt.AlphaComposite)37 Composite (java.awt.Composite)15 Graphics2D (java.awt.Graphics2D)13 Paint (java.awt.Paint)9 BufferedImage (java.awt.image.BufferedImage)7 GradientPaint (java.awt.GradientPaint)5 LinearGradientPaint (java.awt.LinearGradientPaint)4 Point (java.awt.Point)3 AffineTransform (java.awt.geom.AffineTransform)3 Rectangle2D (java.awt.geom.Rectangle2D)3 Spritesheet (de.gurkenlabs.litiengine.graphics.Spritesheet)2 Image (java.awt.Image)2 RadialGradientPaint (java.awt.RadialGradientPaint)2 TexturePaint (java.awt.TexturePaint)2 NoninvertibleTransformException (java.awt.geom.NoninvertibleTransformException)2 JFreeChart (org.jfree.chart.JFreeChart)2 Plot (org.jfree.chart.plot.Plot)2 XORComposite (sun.java2d.loops.XORComposite)2 PixelToParallelogramConverter (sun.java2d.pipe.PixelToParallelogramConverter)2 TextPipe (sun.java2d.pipe.TextPipe)2