Example usage for java.awt AlphaComposite Src

List of usage examples for java.awt AlphaComposite Src

Introduction

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

Prototype

AlphaComposite Src

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

Click Source Link

Document

AlphaComposite object that implements the opaque SRC rule with an alpha of 1.0f.

Usage

From source file:ch.rasc.downloadchart.DownloadChartServlet.java

private static void writeImage(HttpServletResponse response, byte[] imageData, Integer width, Integer height,
        String formatName) throws IOException {

    BufferedImage originalImage = ImageIO.read(new ByteArrayInputStream(imageData));
    Dimension newDimension = calculateDimension(originalImage, width, height);

    if (newDimension != null) {
        int type = originalImage.getType() == 0 ? BufferedImage.TYPE_INT_ARGB : originalImage.getType();
        BufferedImage resizedImage = new BufferedImage(newDimension.width, newDimension.height, type);
        Graphics2D g = resizedImage.createGraphics();
        g.drawImage(originalImage, 0, 0, newDimension.width, newDimension.height, null);
        g.dispose();//from   w w  w . j a  v a  2  s  . c o  m
        g.setComposite(AlphaComposite.Src);

        g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
        g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        ImageIO.write(resizedImage, formatName, response.getOutputStream());
    } else {
        if ("png".equals(formatName)) {
            response.getOutputStream().write(imageData);
        } else {
            ImageIO.write(originalImage, "gif", response.getOutputStream());
        }
    }
}

From source file:org.deegree.test.gui.StressTestController.java

private void renderResizedImage(HttpServletResponse response, String shot, int width, int height)
        throws IOException {
    BufferedImage originalImage = ImageIO.read(new File(shot));

    BufferedImage scaledImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics2D graphics = scaledImage.createGraphics();
    graphics.setComposite(AlphaComposite.Src);
    graphics.drawImage(originalImage, 0, 0, width, height, null);
    graphics.dispose();/*from www.  j  ava  2 s . com*/

    response.setContentType("image/jpeg");
    OutputStream out = response.getOutputStream();
    ImageIO.write(scaledImage, "jpg", out);
    out.close();

}

From source file:com.salesmanager.core.util.ProductImageUtil.java

public BufferedImage resize(BufferedImage image, int width, int height) {
    int type = image.getType() == 0 ? BufferedImage.TYPE_INT_ARGB : image.getType();
    BufferedImage resizedImage = new BufferedImage(width, height, type);
    Graphics2D g = resizedImage.createGraphics();
    g.setComposite(AlphaComposite.Src);
    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g.drawImage(image, 0, 0, width, height, null);
    g.dispose();//from  w ww  .j a  v a2 s. co  m
    return resizedImage;
}

From source file:fr.fg.server.core.TerritoryManager.java

private static BufferedImage createTerritoryMap(int idSector) {
    List<Area> areas = new ArrayList<Area>(DataAccess.getAreasBySector(idSector));

    float[][] points = new float[areas.size()][2];
    int[] dominatingAllies = new int[areas.size()];
    int i = 0;/*from  www .  java2  s  . c  o m*/
    for (Area area : areas) {
        points[i][0] = area.getX() * MAP_SCALE;
        points[i][1] = area.getY() * MAP_SCALE;
        dominatingAllies[i] = area.getIdDominatingAlly();
        i++;
    }

    Hull hull = new Hull(points);
    MPolygon hullPolygon = hull.getRegion();
    float[][] newPoints = new float[points.length + hullPolygon.count()][2];
    System.arraycopy(points, 0, newPoints, 0, points.length);

    float[][] hullCoords = hullPolygon.getCoords();

    for (i = 0; i < hullPolygon.count(); i++) {
        double angle = Math.atan2(hullCoords[i][1], hullCoords[i][0]);
        double length = Math.sqrt(hullCoords[i][0] * hullCoords[i][0] + hullCoords[i][1] * hullCoords[i][1]);

        newPoints[i + points.length][0] = (float) (Math.cos(angle) * (length + 8 * MAP_SCALE));
        newPoints[i + points.length][1] = (float) (Math.sin(angle) * (length + 8 * MAP_SCALE));
    }

    points = newPoints;

    Voronoi voronoi = new Voronoi(points);
    Delaunay delaunay = new Delaunay(points);

    // Dcoupage en rgions
    MPolygon[] regions = voronoi.getRegions();

    // Calcule le rayon de la galaxie
    int radius = 0;

    for (Area area : areas) {
        radius = Math.max(radius, area.getX() * area.getX() + area.getY() * area.getY());
    }

    radius = (int) Math.floor(Math.sqrt(radius) * MAP_SCALE) + 10 * MAP_SCALE;
    int diameter = 2 * radius + 1;

    // Construit l'image avec les quadrants
    BufferedImage territoriesImage = new BufferedImage(diameter, diameter, BufferedImage.TYPE_INT_ARGB);

    Graphics2D g = (Graphics2D) territoriesImage.getGraphics();

    // Affecte une couleur  chaque alliance
    HashMap<Integer, Color> alliesColors = new HashMap<Integer, Color>();

    for (Area area : areas) {
        int idDominatingAlly = area.getIdDominatingAlly();
        if (idDominatingAlly != 0)
            alliesColors.put(idDominatingAlly,
                    Ally.TERRITORY_COLORS[DataAccess.getAllyById(idDominatingAlly).getColor()]);
    }

    Polygon[] polygons = new Polygon[regions.length];
    for (i = 0; i < areas.size(); i++) {
        if (dominatingAllies[i] != 0) {
            polygons[i] = createPolygon(regions[i].getCoords(), radius + 1, 3);
        }
    }

    // Dessine tous les secteurs
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);

    for (i = 0; i < areas.size(); i++) {
        if (dominatingAllies[i] == 0)
            continue;

        Polygon p = polygons[i];

        // Dessine le polygone
        g.setColor(alliesColors.get(dominatingAllies[i]));
        g.fill(p);

        // Rempli les espaces entre les polygones adjacents qui
        // correspondent au territoire d'une mme alliance
        int[] linkedRegions = delaunay.getLinked(i);
        for (int j = 0; j < linkedRegions.length; j++) {
            int linkedRegion = linkedRegions[j];

            if (linkedRegion >= areas.size())
                continue;

            if (dominatingAllies[i] == dominatingAllies[linkedRegion]) {
                if (linkedRegion <= i)
                    continue;

                float[][] coords1 = regions[i].getCoords();
                float[][] coords2 = regions[linkedRegion].getCoords();

                int junctionIndex = 0;
                int[][] junctions = new int[2][2];

                search: for (int k = 0; k < coords1.length; k++) {
                    for (int l = 0; l < coords2.length; l++) {
                        if (coords1[k][0] == coords2[l][0] && coords1[k][1] == coords2[l][1]) {
                            junctions[junctionIndex][0] = k;
                            junctions[junctionIndex][1] = l;

                            junctionIndex++;

                            if (junctionIndex == 2) {
                                int[] xpts = new int[] { polygons[i].xpoints[junctions[0][0]],
                                        polygons[linkedRegion].xpoints[junctions[0][1]],
                                        polygons[linkedRegion].xpoints[junctions[1][1]],
                                        polygons[i].xpoints[junctions[1][0]], };
                                int[] ypts = new int[] { polygons[i].ypoints[junctions[0][0]],
                                        polygons[linkedRegion].ypoints[junctions[0][1]],
                                        polygons[linkedRegion].ypoints[junctions[1][1]],
                                        polygons[i].ypoints[junctions[1][0]], };

                                Polygon border = new Polygon(xpts, ypts, 4);
                                g.setStroke(new BasicStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND));
                                g.fill(border);
                                g.draw(border);
                                break search;
                            }
                            break;
                        }
                    }
                }
            }
        }
    }

    // Dessine des lignes de contours des territoires
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    for (i = 0; i < areas.size(); i++) {
        if (dominatingAllies[i] == 0)
            continue;

        g.setStroke(new BasicStroke(1.5f));
        g.setColor(alliesColors.get(dominatingAllies[i]).brighter().brighter());

        float[][] coords1 = regions[i].getCoords();

        lines: for (int j = 0; j < coords1.length; j++) {
            int[] linkedRegions = delaunay.getLinked(i);
            for (int k = 0; k < linkedRegions.length; k++) {
                int linkedRegion = linkedRegions[k];

                if (linkedRegion >= areas.size())
                    continue;

                if (dominatingAllies[i] == dominatingAllies[linkedRegion]) {
                    float[][] coords2 = regions[linkedRegion].getCoords();

                    for (int m = 0; m < coords2.length; m++) {
                        if (coords1[j][0] == coords2[m][0] && coords1[j][1] == coords2[m][1]
                                && ((coords1[(j + 1) % coords1.length][0] == coords2[(m + 1)
                                        % coords2.length][0]
                                        && coords1[(j + 1) % coords1.length][1] == coords2[(m + 1)
                                                % coords2.length][1])
                                        || (coords1[(j + 1)
                                                % coords1.length][0] == coords2[(m - 1 + coords2.length)
                                                        % coords2.length][0]
                                                && coords1[(j + 1)
                                                        % coords1.length][1] == coords2[(m - 1 + coords2.length)
                                                                % coords2.length][1]))) {
                            continue lines;
                        }
                    }
                }
            }

            g.drawLine(Math.round(polygons[i].xpoints[j]), Math.round(polygons[i].ypoints[j]),
                    Math.round(polygons[i].xpoints[(j + 1) % coords1.length]),
                    Math.round(polygons[i].ypoints[(j + 1) % coords1.length]));
        }

        for (int j = 0; j < coords1.length; j++) {
            int neighbours = 0;
            int lastNeighbourRegion = -1;
            int neighbourCoordsIndex = -1;

            int[] linkedRegions = delaunay.getLinked(i);
            for (int k = 0; k < linkedRegions.length; k++) {
                int linkedRegion = linkedRegions[k];

                if (linkedRegion >= areas.size())
                    continue;

                if (dominatingAllies[i] == dominatingAllies[linkedRegion]) {
                    float[][] coords2 = regions[linkedRegion].getCoords();

                    for (int m = 0; m < coords2.length; m++) {
                        if (coords1[j][0] == coords2[m][0] && coords1[j][1] == coords2[m][1]) {
                            neighbours++;
                            lastNeighbourRegion = linkedRegion;
                            neighbourCoordsIndex = m;
                            break;
                        }
                    }
                }
            }

            if (neighbours == 1) {
                g.drawLine(Math.round(polygons[i].xpoints[j]), Math.round(polygons[i].ypoints[j]),
                        Math.round(polygons[lastNeighbourRegion].xpoints[neighbourCoordsIndex]),
                        Math.round(polygons[lastNeighbourRegion].ypoints[neighbourCoordsIndex]));
            }
        }
    }

    BufferedImage finalImage = new BufferedImage(diameter, diameter, BufferedImage.TYPE_INT_ARGB);

    g = (Graphics2D) finalImage.getGraphics();

    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, .15f));
    g.drawImage(territoriesImage, 0, 0, null);
    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, .5f));

    // Charge la police pour afficher le nom des alliances
    try {
        Font textFont = Font.createFont(Font.TRUETYPE_FONT,
                Action.class.getClassLoader().getResourceAsStream("fr/fg/server/resources/TinDog.ttf"));
        textFont = textFont.deriveFont(12f).deriveFont(Font.BOLD);
        g.setFont(textFont);
    } catch (Exception e) {
        LoggingSystem.getServerLogger().warn("Could not load quadrant map font.", e);
    }
    FontMetrics fm = g.getFontMetrics();

    ArrayList<Integer> closedRegions = new ArrayList<Integer>();

    for (i = 0; i < areas.size(); i++) {
        if (dominatingAllies[i] == 0 || closedRegions.contains(i))
            continue;

        ArrayList<Integer> allyRegions = new ArrayList<Integer>();
        ArrayList<Integer> openRegions = new ArrayList<Integer>();

        openRegions.add(i);

        while (openRegions.size() > 0) {
            int currentRegion = openRegions.remove(0);
            allyRegions.add(currentRegion);
            closedRegions.add(currentRegion);

            int[] linkedRegions = delaunay.getLinked(currentRegion);

            for (int k = 0; k < linkedRegions.length; k++) {
                int linkedRegion = linkedRegions[k];

                if (linkedRegion >= areas.size() || openRegions.contains(linkedRegion)
                        || allyRegions.contains(linkedRegion))
                    continue;

                if (dominatingAllies[i] == dominatingAllies[linkedRegion])
                    openRegions.add(linkedRegion);
            }
        }

        Area area = areas.get(i);
        long xsum = 0;
        long ysum = 0;

        for (int k = 0; k < allyRegions.size(); k++) {
            int allyRegion = allyRegions.get(k);
            area = areas.get(allyRegion);

            xsum += area.getX();
            ysum += area.getY();
        }

        int x = (int) (xsum / allyRegions.size()) * MAP_SCALE + radius + 1;
        int y = (int) (-ysum / allyRegions.size()) * MAP_SCALE + radius + 1;
        ;

        Point point = new Point(x, y);
        boolean validLocation = false;
        for (int k = 0; k < allyRegions.size(); k++) {
            int allyRegion = allyRegions.get(k);

            if (polygons[allyRegion].contains(point)) {
                validLocation = true;
                break;
            }
        }

        if (validLocation) {
            if (allyRegions.size() == 1)
                y -= 14;
        } else {
            int xmid = (int) (xsum / allyRegions.size());
            int ymid = (int) (ysum / allyRegions.size());

            area = areas.get(i);
            int dx = area.getX() - xmid;
            int dy = area.getY() - ymid;
            int distance = dx * dx + dy * dy;

            int nearestAreaIndex = i;
            int nearestDistance = distance;

            for (int k = 0; k < allyRegions.size(); k++) {
                int allyRegion = allyRegions.get(k);

                area = areas.get(allyRegion);
                dx = area.getX() - xmid;
                dy = area.getY() - ymid;
                distance = dx * dx + dy * dy;

                if (distance < nearestDistance) {
                    nearestAreaIndex = allyRegion;
                    nearestDistance = distance;
                }
            }

            area = areas.get(nearestAreaIndex);
            x = area.getX() * MAP_SCALE + radius + 1;
            y = -area.getY() * MAP_SCALE + radius - 13;
        }

        // Dessine le tag de l'alliance
        String allyTag = "[ " + DataAccess.getAllyById(dominatingAllies[i]).getTag() + " ]";
        g.setColor(Color.BLACK);
        g.drawString(allyTag, x - fm.stringWidth(allyTag) / 2 + 1, y);
        g.setColor(alliesColors.get(dominatingAllies[i]));
        g.drawString(allyTag, x - fm.stringWidth(allyTag) / 2, y);
    }

    return finalImage;
}

From source file:at.tugraz.sss.serv.SSFileU.java

public static void scalePNGAndWrite(final BufferedImage buffImage, final String pngFilePath,
        final Integer width, final Integer height) throws IOException {

    final BufferedImage scaledThumb = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    final Graphics2D graphics2D = scaledThumb.createGraphics();

    graphics2D.setComposite(AlphaComposite.Src);
    graphics2D.drawImage(buffImage, 0, 0, width, height, null);
    graphics2D.dispose();//w ww.jav a 2  s. c o  m

    ImageIO.write(scaledThumb, SSFileExtE.png.toString(), new File(pngFilePath));
}

From source file:com.cmart.PageControllers.SellItemImagesController.java

private static BufferedImage resizeImageWithHint(BufferedImage originalImage, int type, int width, int height) {

    BufferedImage resizedImage = new BufferedImage(width, width, type);
    Graphics2D g = resizedImage.createGraphics();
    g.drawImage(originalImage, 0, 0, width, width, null);
    g.dispose();/* w  w w .  ja  va 2  s .  c o  m*/
    g.setComposite(AlphaComposite.Src);

    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    return resizedImage;
}

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;//w  ww. j  av a 2  s.c  o  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:de.tuttas.restful.SchuelerManager.java

private BufferedImage createResizedCopy(Image originalImage, int scaledWidth, int scaledHeight,
        boolean preserveAlpha) {
    int imageType = preserveAlpha ? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB;
    BufferedImage scaledBI = new BufferedImage(scaledWidth, scaledHeight, imageType);
    Graphics2D g = scaledBI.createGraphics();
    if (preserveAlpha) {
        g.setComposite(AlphaComposite.Src);
    }// w  w w. j a  v a 2s  .  c o m
    g.drawImage(originalImage, 0, 0, scaledWidth, scaledHeight, null);
    g.dispose();
    return scaledBI;
}

From source file:com.pronoiahealth.olhie.server.services.BookCoverImageService.java

/**
 * Resize an image//from ww w  .j  a v  a  2s  .  c  o m
 * 
 * @param originalImage
 * @param width
 * @param height
 * @param type
 * @return
 */
private BufferedImage resize(BufferedImage originalImage, int width, int height, int type) {
    BufferedImage resizedImage = new BufferedImage(width, height, type);
    Graphics2D g = resizedImage.createGraphics();
    try {
        g.setComposite(AlphaComposite.Src);
        g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
        g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g.drawImage(originalImage, 0, 0, width, height, null);
    } finally {
        if (g != null) {
            g.dispose();
        }
    }

    return resizedImage;
}

From source file:com.zacwolf.commons.email.Email.java

public static BufferedImage makeRoundedBanner(BufferedImage image, int cornerRadius) {
    int w = image.getWidth();
    int h = image.getHeight() + 10;
    BufferedImage output = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = output.createGraphics();
    g2.setComposite(AlphaComposite.Src);
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setColor(Color.WHITE);/*from  w w w  .  j av  a  2 s. co  m*/
    g2.fill(new RoundRectangle2D.Float(0, 0, w, h, cornerRadius, cornerRadius));
    g2.setComposite(AlphaComposite.SrcAtop);
    g2.drawImage(image, 0, 0, null);
    g2.setComposite(AlphaComposite.SrcOver);
    //               g2.setColor(new Color(153,153,153));//slight grey border
    //               g2.drawRoundRect(0, 0, w-1, h, cornerRadius, cornerRadius);
    g2.dispose();
    return output.getSubimage(0, 0, image.getWidth(), image.getHeight());
}