Example usage for java.awt AlphaComposite DST_OVER

List of usage examples for java.awt AlphaComposite DST_OVER

Introduction

In this page you can find the example usage for java.awt AlphaComposite DST_OVER.

Prototype

int DST_OVER

To view the source code for java.awt AlphaComposite DST_OVER.

Click Source Link

Document

The destination is composited over the source and the result replaces the destination (Porter-Duff Destination Over Source rule).

Usage

From source file:MainClass.java

public void paint(Graphics g) {

    Graphics2D g2 = (Graphics2D) g;

    RenderingHints rh = g2.getRenderingHints();
    rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHints(rh);/*from   www .j  a  v a  2 s .  c om*/

    int x = 40, y = 40;

    g.setColor(Color.red);
    g.fillOval(x, y, 50, 50);

    Composite old = g2.getComposite();

    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.DST_OVER));

    g.setColor(Color.green);
    g.fillOval(x + 30, y + 30, 30, 30);

    g2.setComposite(old);

    g.setColor(Color.black);
    g.drawString("AlphaComposite.DST_OVER", x, y + 80);

}

From source file:Composite.java

public int getRule(int rule) {
    int alphaComp = 0;
    switch (rule) {
    case 0://from ww w  . ja v  a 2 s  .c o m
        alphaComp = AlphaComposite.SRC;
        break;
    case 1:
        alphaComp = AlphaComposite.DST_IN;
        break;
    case 2:
        alphaComp = AlphaComposite.DST_OUT;
        break;
    case 3:
        alphaComp = AlphaComposite.DST_OVER;
        break;
    case 4:
        alphaComp = AlphaComposite.SRC_IN;
        break;
    case 5:
        alphaComp = AlphaComposite.SRC_OVER;
        break;
    case 6:
        alphaComp = AlphaComposite.SRC_OUT;
        break;
    case 7:
        alphaComp = AlphaComposite.CLEAR;
        break;
    }
    return alphaComp;
}

From source file:org.openmeetings.app.data.record.BatikMethods.java

public void paintEllipse2D(Graphics2D g2d, double x, double y, double width, double height, Color linecoler,
        int thickness, Color fillColor, float alpha) throws Exception {

    g2d.setStroke(new BasicStroke(thickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));

    int[] rules = new int[8];

    //all possible Compositing Rules:
    rules[0] = AlphaComposite.SRC_OVER;
    rules[1] = AlphaComposite.DST_OVER;
    rules[2] = AlphaComposite.CLEAR;
    rules[3] = AlphaComposite.SRC;
    rules[4] = AlphaComposite.SRC_IN;
    rules[5] = AlphaComposite.DST_IN;
    rules[6] = AlphaComposite.SRC_OUT;
    rules[7] = AlphaComposite.DST_OUT;

    g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, alpha));

    //int x, int y, int width, int height

    if (linecoler != null) {
        g2d.setPaint(linecoler);/*from  ww w.  ja  va 2s  .  com*/
        g2d.draw(new Ellipse2D.Double(x, y, width, height));
    }

    if (fillColor != null) {
        g2d.setPaint(fillColor);
        g2d.fill(new Ellipse2D.Double(x, y, width, height));
    }

}

From source file:org.openmeetings.app.data.record.BatikMethods.java

public void paintRect2D(Graphics2D g2d, double x, double y, double width, double height, Color linecoler,
        int thickness, Color fillColor, float alpha) throws Exception {

    g2d.setStroke(new BasicStroke(thickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));

    int[] rules = new int[8];

    //all possible Compositing Rules:
    rules[0] = AlphaComposite.SRC_OVER;
    rules[1] = AlphaComposite.DST_OVER;
    rules[2] = AlphaComposite.CLEAR;
    rules[3] = AlphaComposite.SRC;
    rules[4] = AlphaComposite.SRC_IN;
    rules[5] = AlphaComposite.DST_IN;
    rules[6] = AlphaComposite.SRC_OUT;
    rules[7] = AlphaComposite.DST_OUT;

    g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, alpha));

    //int x, int y, int width, int height

    if (linecoler != null) {
        g2d.setPaint(linecoler);/*from w  ww .j a  va  2  s  . co m*/
        g2d.draw(new Rectangle2D.Double(x, y, width, height));
    }

    if (fillColor != null) {
        g2d.setPaint(fillColor);
        g2d.fill(new Rectangle2D.Double(x, y, width, height));
    }

}

From source file:org.openmeetings.app.data.record.BatikMethods.java

public void drawThickLine2DPaint(Graphics2D g2d, double x1, double y1, double x2, double y2, int width, Color c,
        double xObj, double yObj, float alpha) throws Exception {
    g2d.setPaint(c);//from   ww w  .  j  av  a 2 s  .  c om

    int[] rules = new int[8];

    //all possible Compositing Rules:
    rules[0] = AlphaComposite.SRC_OVER;
    rules[1] = AlphaComposite.DST_OVER;
    rules[2] = AlphaComposite.CLEAR;
    rules[3] = AlphaComposite.SRC;
    rules[4] = AlphaComposite.SRC_IN;
    rules[5] = AlphaComposite.DST_IN;
    rules[6] = AlphaComposite.SRC_OUT;
    rules[7] = AlphaComposite.DST_OUT;

    g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, alpha));
    g2d.setStroke(new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL));
    Line2D line = new Line2D.Double(x1, y1, x2, y2);
    g2d.draw(line);
}

From source file:org.openmeetings.app.data.record.BatikMethods.java

public void drawThickLine2D(Graphics2D g2d, double x1, double y1, double x2, double y2, int width, Color c,
        double xObj, double yObj, float alpha) throws Exception {
    g2d.setPaint(c);/*from w w  w .  j av a  2s  .  c  o m*/

    int[] rules = new int[8];

    //all possible Compositing Rules:
    rules[0] = AlphaComposite.SRC_OVER;
    rules[1] = AlphaComposite.DST_OVER;
    rules[2] = AlphaComposite.CLEAR;
    rules[3] = AlphaComposite.SRC;
    rules[4] = AlphaComposite.SRC_IN;
    rules[5] = AlphaComposite.DST_IN;
    rules[6] = AlphaComposite.SRC_OUT;
    rules[7] = AlphaComposite.DST_OUT;

    g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, alpha));
    g2d.setStroke(new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL));
    Line2D line = new Line2D.Double(x1 + xObj, y1 + yObj, x2 + xObj, y2 + yObj);
    g2d.draw(line);
}

From source file:org.openmeetings.app.data.record.BatikMethods.java

public void drawArrow(SVGGraphics2D g2d, GeomPoint start, GeomPoint end, float thickness, float alpha,
        Color linecoler, Color fillColor) {

    if (start.equals(end))
        return;//from   w ww .j av  a 2 s  . co  m

    //      (double edgeControlPosition, double edgeControlSize,
    //            double headLength, double headWidth, double shaftControlPosition,
    //            double shaftControlSize, float shaftPosition, double shaftThickness)
    ArrowStyle arrowStyle = new ArrowStyle(0.5, 0.5, thickness * 5, thickness * 5, 0.5, 0.5, 0, thickness);

    GeomPoint fullVect = end.subtract(start);
    double halfWidth = (arrowStyle.headWidth != -1) ? arrowStyle.headWidth / 2 : arrowStyle.headLength / 2;

    //Figure out the line start/end points
    GeomPoint startNorm = new GeomPoint();
    startNorm.setLocation(fullVect.getY(), -fullVect.getX());
    startNorm.normalize(arrowStyle.shaftThickness / 2);
    GeomPoint start1 = start.add(startNorm);
    GeomPoint start2 = start.subtract(startNorm);
    GeomPoint end1 = end.add(startNorm);
    GeomPoint end2 = end.subtract(startNorm);

    //log.debug("startNorm: "+startNorm.toString());
    //log.debug("start1: "+start1.toString());
    //log.debug("start2: "+start2.toString());
    //log.debug("end1: "+end1.toString());
    //log.debug("end2: "+end2.toString());

    //figure out where the arrow head starts
    GeomPoint headPnt = fullVect.clone();
    //log.debug("headPnt 1: "+headPnt.toString());
    //log.debug("headPnt.length 1: "+headPnt.length());
    //log.debug("arrowStyle.headLength 1: "+arrowStyle.headLength);
    headPnt.normalize(headPnt.length() - arrowStyle.headLength);
    //log.debug("headPnt 2: "+headPnt.toString());
    headPnt = headPnt.add(start);
    //log.debug("headPnt 3: "+headPnt.toString());

    //calculate the arrowhead corners
    GeomPoint headPntNorm = startNorm.clone();
    //log.debug("headPntNorm ^^: "+headPntNorm.toString());
    //log.debug("halfWidth ^^: "+halfWidth);
    headPntNorm.normalize(halfWidth);
    //log.debug("headPntNorm: "+headPntNorm.toString());
    GeomPoint edge1 = headPnt.add(headPntNorm);
    GeomPoint edge2 = headPnt.subtract(headPntNorm);

    //log.debug("edge1: "+edge1.toString());
    //log.debug("edge2: "+edge2.toString());

    //Figure out where the arrow connects the the shaft, then calc the intersections
    GeomPoint shaftCenter = GeomPoint.interpolate(end, headPnt, arrowStyle.shaftPosition);
    //log.debug("end"+end.toString());
    //log.debug("headPnt: "+headPnt.toString());
    //log.debug("arrowStyle.shaftPosition: "+arrowStyle.shaftPosition);
    //log.debug("shaftCenter: "+shaftCenter);
    //log.debug("edge1: "+edge1);
    //shaftCenter.setLocation(185.857864376269, 185.857864376269);
    GeomPoint inter1 = GeomPoint.getLineIntersection(start1, end1, shaftCenter, edge1);
    GeomPoint inter2 = GeomPoint.getLineIntersection(start2, end2, shaftCenter, edge2);

    //log.debug("inter1: "+inter1.toString());
    //log.debug("inter2: "+inter2.toString());

    //Figure out the control points
    GeomPoint edgeCenter = GeomPoint.interpolate(end, headPnt, (float) arrowStyle.edgeControlPosition);
    GeomPoint edgeNorm = startNorm.clone();
    edgeNorm.normalize(halfWidth * arrowStyle.edgeControlSize);
    //log.debug("halfWidth*arrowStyle.edgeControlSize: "+(halfWidth*arrowStyle.edgeControlSize));
    //log.debug("edgeNorm: "+edgeNorm.toString());
    GeomPoint edgeCntrl1 = edgeCenter.add(edgeNorm);
    GeomPoint edgeCntrl2 = edgeCenter.subtract(edgeNorm);

    //log.debug("edgeCntrl1: "+edgeCntrl1.toString());
    //log.debug("edgeCntrl2: "+edgeCntrl2.toString());

    g2d.setPaint(new Color(255, 0, 0));

    //      graphics.moveTo(start1.x,start1.y);
    //      graphics.lineTo(inter1.x,inter1.y);
    //      graphics.lineTo(edge1.x,edge1.y);
    //      graphics.curveTo(edgeCntrl1.x,edgeCntrl1.y,end.x,end.y);
    //      graphics.curveTo(edgeCntrl2.x,edgeCntrl2.y,edge2.x,edge2.y);
    //      graphics.lineTo(inter2.x,inter2.y);
    //      graphics.lineTo(start2.x,start2.y);
    //      graphics.lineTo(start1.x,start1.y);

    //      log.debug("moveTo"+start1.x+","+start1.y);
    //      log.debug("lineTo"+inter1.x+","+inter1.y);
    //      log.debug("lineTo"+edge1.x+","+edge1.y);
    //      log.debug("quadTo"+edgeCntrl1.x+","+edgeCntrl1.y+","+end.x+","+end.y);
    //      log.debug("quadTo"+edgeCntrl2.x+","+edgeCntrl2.y+","+edge2.x+","+edge2.y);
    //      log.debug("lineTo"+inter2.x+","+inter2.y);
    //      log.debug("lineTo"+start2.x+","+start2.y);
    //      log.debug("lineTo"+start1.x+","+start1.y);

    GeneralPath graphics = new GeneralPath();
    graphics.moveTo(start1.x, start1.y);
    graphics.lineTo(inter1.x, inter1.y);
    graphics.lineTo(edge1.x, edge1.y);
    graphics.quadTo(edgeCntrl1.x, edgeCntrl1.y, end.x, end.y);
    graphics.quadTo(edgeCntrl2.x, edgeCntrl2.y, edge2.x, edge2.y);
    graphics.lineTo(inter2.x, inter2.y);
    graphics.lineTo(start2.x, start2.y);
    graphics.lineTo(start1.x, start1.y);
    graphics.closePath();

    int[] rules = new int[8];

    //all possible Compositing Rules:
    rules[0] = AlphaComposite.SRC_OVER;
    rules[1] = AlphaComposite.DST_OVER;
    rules[2] = AlphaComposite.CLEAR;
    rules[3] = AlphaComposite.SRC;
    rules[4] = AlphaComposite.SRC_IN;
    rules[5] = AlphaComposite.DST_IN;
    rules[6] = AlphaComposite.SRC_OUT;
    rules[7] = AlphaComposite.DST_OUT;

    g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, alpha));
    g2d.setStroke(new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL));

    if (linecoler != null) {
        g2d.setPaint(linecoler);
        g2d.draw(graphics);
    }

    if (fillColor != null) {
        g2d.setPaint(fillColor);
        g2d.fill(graphics);
    }

}

From source file:nl.b3p.kaartenbalie.service.KBImageTool.java

/** Combines GIF, TIFF or PNG images. Combining these images is different from the JPG image types since these
 * has to use an other imageType: BufferedImage.TYPE_INT_ARGB_PRE.
 *
 * @param images BufferedImage array with the images tha have to be combined.
 *
 * @return BufferedImage//ww w  .j  a  v  a2  s  .  c  o m
 */
// <editor-fold defaultstate="" desc="combineOtherImages(BufferedImage [] images) method.">
private static BufferedImage combineOtherImages(BufferedImage[] images) {
    int width = images[0].getWidth();
    int height = images[0].getHeight();

    BufferedImage newBufIm = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB_PRE);
    Graphics2D gbi = newBufIm.createGraphics();

    gbi.drawImage(images[0], 0, 0, null);
    gbi.setComposite(AlphaComposite.getInstance(AlphaComposite.DST_OVER, 1.0f));

    for (int i = 1; i < images.length; i++) {
        gbi.drawImage(images[i], 0, 0, null);
    }
    return newBufIm;
}