Example usage for java.awt Color getAlpha

List of usage examples for java.awt Color getAlpha

Introduction

In this page you can find the example usage for java.awt Color getAlpha.

Prototype

public int getAlpha() 

Source Link

Document

Returns the alpha component in the range 0-255.

Usage

From source file:haven.Utils.java

public static Color blendcol(Color in, Color bl) {
    int f1 = bl.getAlpha();
    int f2 = 255 - bl.getAlpha();
    return (new Color(((in.getRed() * f2) + (bl.getRed() * f1)) / 255,
            ((in.getGreen() * f2) + (bl.getGreen() * f1)) / 255,
            ((in.getBlue() * f2) + (bl.getBlue() * f1)) / 255, in.getAlpha()));
}

From source file:com.gargoylesoftware.htmlunit.javascript.host.canvas.rendering.AwtRenderingBackend.java

/**
 * {@inheritDoc}//from  w  ww  .  j  av a 2s  . co m
 */
public byte[] getBytes(final int width, final int height, final int sx, final int sy) {
    final byte[] array = new byte[width * height * 4];
    int index = 0;
    for (int x = 0; x < width; x++) {
        for (int y = 0; y < height; y++) {
            final Color c = new Color(image_.getRGB(sx + x, sy + y), true);
            array[index++] = (byte) c.getRed();
            array[index++] = (byte) c.getGreen();
            array[index++] = (byte) c.getBlue();
            array[index++] = (byte) c.getAlpha();
        }
    }
    return array;
}

From source file:haven.Utils.java

public static Color preblend(Color c1, Color c2) {
    double a1 = c1.getAlpha() / 255.0;
    double a2 = c2.getAlpha() / 255.0;
    /* I can't help but feel that this should be possible to
     * express in some simpler form, but I can't see how. */
    double ac = a1 + a2 - (a1 * a2);
    return (new Color((int) Math.round((((c2.getRed() * a2) - (c1.getRed() * a2)) / ac) + c1.getRed()),
            (int) Math.round((((c2.getGreen() * a2) - (c1.getGreen() * a2)) / ac) + c1.getGreen()),
            (int) Math.round((((c2.getBlue() * a2) - (c1.getBlue() * a2)) / ac) + c1.getBlue()),
            (int) Math.round(ac * 255)));
}

From source file:org.jfree.eastwood.GXYPlot.java

/**
 * Draws the gridlines for the plot's primary range axis, if they are
 * visible.//from   w  w  w.  j av  a  2  s.c  om
 *
 * @param g2  the graphics device.
 * @param area  the data area.
 * @param ticks  the ticks.
 *
 * @see #drawDomainGridlines(Graphics2D, Rectangle2D, List)
 */
protected void drawRangeGridlines(Graphics2D g2, Rectangle2D area, List ticks) {

    // no renderer, no gridlines...
    if (getRenderer() == null) {
        return;
    }

    // draw the range grid lines, if any...
    if (isRangeGridlinesVisible() && this.yAxisStepSize > 0) {
        Stroke gridStroke = getRangeGridlineStroke();
        Paint gridPaint = getRangeGridlinePaint();
        ValueAxis axis = getRangeAxis();
        if (axis != null) {
            double lower = axis.getRange().getLowerBound();
            double upper = axis.getRange().getUpperBound();
            double y = lower;
            while (y <= upper) {
                Paint paint = gridPaint;
                if ((y == lower || y == upper) && gridPaint instanceof Color) {
                    Color c = (Color) gridPaint;
                    paint = new Color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha() / 3);
                }
                getRenderer().drawRangeLine(g2, this, getRangeAxis(), area, y, paint, gridStroke);
                y += this.yAxisStepSize;
            }
        }
    }
}

From source file:org.jfree.eastwood.GXYPlot.java

/**
 * Draws the gridlines for the plot, if they are visible.
 *
 * @param g2  the graphics device./*  www .ja  va  2  s.co  m*/
 * @param dataArea  the data area.
 * @param ticks  the ticks.
 *
 * @see #drawRangeGridlines(Graphics2D, Rectangle2D, List)
 */
protected void drawDomainGridlines(Graphics2D g2, Rectangle2D dataArea, List ticks) {

    // no renderer, no gridlines...
    if (getRenderer() == null) {
        return;
    }

    // draw the domain grid lines, if any...
    if (isDomainGridlinesVisible() && this.xAxisStepSize > 0) {
        Stroke gridStroke = getDomainGridlineStroke();
        Paint gridPaint = getDomainGridlinePaint();
        if ((gridStroke != null) && (gridPaint != null)) {
            ValueAxis axis = getDomainAxis();
            if (axis != null) {
                double lower = axis.getRange().getLowerBound();
                double upper = axis.getRange().getUpperBound();
                double x = lower;
                while (x <= upper) {
                    Paint paint = gridPaint;
                    if ((x == lower || x == upper) && gridPaint instanceof Color) {
                        Color c = (Color) gridPaint;
                        paint = new Color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha() / 3);
                    }
                    try {
                        setDomainGridlinePaint(paint);
                        getRenderer().drawDomainGridLine(g2, this, getDomainAxis(), dataArea, x);
                    } finally {
                        setDomainGridlinePaint(gridPaint);
                    }
                    x += this.xAxisStepSize;
                }
            }
        }
    }
}

From source file:com.rapidminer.gui.plotter.charts.RapidXYBarPainter.java

@Override
public void paintBar(Graphics2D g2, XYBarRenderer renderer, int row, int column, RectangularShape bar,
        RectangleEdge base) {/*  ww  w  . j  av  a 2  s .com*/
    Paint itemPaint = renderer.getItemPaint(row, column);

    Color c0 = null;

    if (itemPaint instanceof Color) {
        c0 = (Color) itemPaint;
    } else {
        c0 = SwingTools.DARK_BLUE;
    }

    // as a special case, if the bar color has alpha == 0, we draw
    // nothing.
    if (c0.getAlpha() == 0) {
        return;
    }

    g2.setPaint(c0);
    g2.fill(new Rectangle2D.Double(bar.getMinX(), bar.getMinY(), bar.getWidth(), bar.getHeight()));

    // draw the outline...
    if (renderer.isDrawBarOutline()) {
        Stroke stroke = renderer.getItemOutlineStroke(row, column);
        Paint paint = renderer.getItemOutlinePaint(row, column);
        if (stroke != null && paint != null) {
            g2.setStroke(stroke);
            g2.setPaint(paint);
            g2.draw(bar);
        }
    }
}

From source file:org.jtrfp.trcl.SkySystem.java

/**
 * @return the suggestedFogColor/* w  ww  .  j av a 2  s. c  o m*/
 */
public Color getSuggestedFogColor() {
    if (suggestedFogColor == null) {
        if (!hasClouds()) {
            return Color.black;
        } else {
            Color l = getHorizonGradientBottom();
            Color r = cloudTexture.getAverageColor();
            return new Color((l.getRed() + r.getRed()) / 2, (l.getGreen() + r.getGreen()) / 2,
                    (l.getBlue() + r.getBlue()) / 2, (l.getAlpha() + r.getAlpha()) / 2);
        }
    } //end if(suggestedFogColor==null)
    return suggestedFogColor;
}

From source file:imageprocessingproject.ImageHistogram.java

public static BufferedImage normalizeImage(BufferedImage image) {
    int height = image.getHeight();
    int width = image.getWidth();

    int r, g, b, minr = 255, ming = 255, minb = 255, maxr = 0, maxg = 0, maxb = 0;
    Color c;

    BufferedImage tempImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

    for (int i = 0; i < width; i++) {
        for (int j = 0; j < height; j++) {
            c = new Color(image.getRGB(i, j));
            if (minr > c.getRed()) {
                minr = c.getRed();//from w  ww.  j a v a2s. c  o m
            }
            if (ming > c.getGreen()) {
                ming = c.getGreen();
            }
            if (minb > c.getBlue()) {
                minb = c.getBlue();
            }
            if (maxr < c.getRed()) {
                maxr = c.getRed();
            }
            if (maxg < c.getGreen()) {
                maxg = c.getGreen();
            }
            if (maxb < c.getBlue()) {
                maxb = c.getBlue();
            }
        }
    }

    for (int i = 0; i < width; i++) {
        for (int j = 0; j < height; j++) {
            c = new Color(image.getRGB(i, j));
            r = (int) ((c.getRed() - minr) * 255 / (maxr - minr));
            g = (int) ((c.getGreen() - ming) * 255 / (maxg - ming));
            b = (int) ((c.getBlue() - minb) * 255 / (maxb - minb));
            tempImage.setRGB(i, j, new Color(r, g, b, c.getAlpha()).getRGB());
        }
    }

    return tempImage;
}

From source file:com.rapidminer.gui.plotter.charts.RapidBarPainter.java

/**
 * Paints a single bar instance./*w  ww  . ja  va2  s  .  co m*/
 * 
 * @param g2
 *            the graphics target.
 * @param renderer
 *            the renderer.
 * @param row
 *            the row index.
 * @param column
 *            the column index.
 * @param bar
 *            the bar
 * @param base
 *            indicates which side of the rectangle is the base of the bar.
 */
@Override
public void paintBar(final Graphics2D g2, final BarRenderer renderer, final int row, final int column,
        final RectangularShape bar, final RectangleEdge base) {
    Paint itemPaint = renderer.getItemPaint(row, column);

    Color c0 = null;

    if (itemPaint instanceof Color) {
        c0 = (Color) itemPaint;
    } else {
        c0 = SwingTools.DARK_BLUE;
    }

    // as a special case, if the bar color has alpha == 0, we draw
    // nothing.
    if (c0.getAlpha() == 0) {
        return;
    }

    g2.setPaint(c0);
    g2.fill(new Rectangle2D.Double(bar.getMinX(), bar.getMinY(), bar.getWidth(), bar.getHeight()));

    // draw the outline...
    if (renderer.isDrawBarOutline()) {
        Stroke stroke = renderer.getItemOutlineStroke(row, column);
        Paint paint = renderer.getItemOutlinePaint(row, column);
        if (stroke != null && paint != null) {
            g2.setStroke(stroke);
            g2.setPaint(paint);
            g2.draw(bar);
        }
    }

}

From source file:omeis.providers.re.HSBStrategy.java

/**
 * Retrieves the color for each active channels.
 * /*  w w  w  .  j  a  va  2 s .  c o  m*/
 * @return the active channel color data.
 */
private List<int[]> getColors() {
    ChannelBinding[] channelBindings = renderer.getChannelBindings();
    List<int[]> colors = new ArrayList<int[]>();

    for (int w = 0; w < channelBindings.length; w++) {
        ChannelBinding cb = channelBindings[w];
        if (cb.getActive()) {
            int[] theNewColor = new int[] { cb.getRed(), cb.getGreen(), cb.getBlue(), cb.getAlpha() };
            colors.add(theNewColor);
        }
    }
    Map<byte[], Integer> overlays = renderer.getOverlays();
    if (overlays != null) {
        for (byte[] overlay : overlays.keySet()) {
            Integer packedColor = overlays.get(overlay);
            Color color = new Color(packedColor);
            colors.add(new int[] { color.getRed(), color.getBlue(), color.getGreen(), color.getAlpha() });
        }
    }
    return colors;
}