Example usage for java.awt.image BufferedImage TYPE_INT_ARGB

List of usage examples for java.awt.image BufferedImage TYPE_INT_ARGB

Introduction

In this page you can find the example usage for java.awt.image BufferedImage TYPE_INT_ARGB.

Prototype

int TYPE_INT_ARGB

To view the source code for java.awt.image BufferedImage TYPE_INT_ARGB.

Click Source Link

Document

Represents an image with 8-bit RGBA color components packed into integer pixels.

Usage

From source file:ca.sqlpower.wabit.report.ResultSetRendererTest.java

/**
 * Tests calling renderSuccess with an empty result set works without
 * throwing any exceptions./*from w  ww .  j av  a 2  s .  co  m*/
 */
public void testRenderSuccessWithEmptyRS() throws Exception {

    ResultSetRenderer renderer = new ResultSetRenderer(query);
    renderer.refresh();

    Image image = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = (Graphics2D) image.getGraphics();
    renderer.renderReportContent(g, 1, 1, 1, 1, false, null);
}

From source file:edu.ku.brc.ui.GraphicsUtils.java

/**
 * Gets a scaled icon and if it doesn't exist it creates one and scales it
 * @param icon image to be scaled//  w w w  . j  a  va 2 s. c  o  m
 * @param iconSize the icon size (Std)
 * @param scaledIconSize the new scaled size in pixels
 * @return the scaled icon
 */
public static Image getScaledImage(final ImageIcon icon, final int newMaxWidth, final int newMaxHeight,
        final boolean maintainRatio) {
    if (icon != null) {
        int dstWidth = newMaxWidth;
        int dstHeight = newMaxHeight;

        int srcWidth = icon.getIconWidth();
        int srcHeight = icon.getIconHeight();

        if ((dstWidth < 0) || (dstHeight < 0)) { //image is nonstd, revert to original size
            dstWidth = icon.getIconWidth();
            dstHeight = icon.getIconHeight();
        }

        if (maintainRatio) {
            double longSideForSource = Math.max(srcWidth, srcHeight);
            double longSideForDest = Math.max(dstWidth, dstHeight);

            double multiplier = longSideForDest / longSideForSource;
            dstWidth = (int) (srcWidth * multiplier);
            dstHeight = (int) (srcHeight * multiplier);
        }

        Image imgMemory = icon.getImage();

        //make sure all pixels in the image were loaded
        imgMemory = new ImageIcon(imgMemory).getImage();

        BufferedImage thumbImage = new BufferedImage(dstWidth, dstHeight, BufferedImage.TYPE_INT_ARGB);

        Graphics2D graphics2D = thumbImage.createGraphics();
        graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                RenderingHints.VALUE_INTERPOLATION_BILINEAR);
        graphics2D.drawImage(imgMemory, 0, 0, dstWidth, dstHeight, 0, 0, srcWidth, srcHeight, null);
        graphics2D.dispose();
        return thumbImage;

    }
    return null;
}

From source file:weka.core.ChartUtils.java

/**
 * Render a combined histogram and box plot chart from summary data
 * //from www  .  j a v  a  2 s. co  m
 * @param width the width of the resulting image
 * @param height the height of the resulting image
 * @param bins the values for the chart
 * @param freqs the corresponding frequencies
 * @param summary the summary stats for the box plot
 * @param outliers an optional list of outliers for the box plot
 * @param additionalArgs optional arguments to the renderer (may be null)
 * @return a buffered image
 * @throws Exception if a problem occurs
 */
public static BufferedImage renderCombinedBoxPlotAndHistogramFromSummaryData(int width, int height,
        List<String> bins, List<Double> freqs, List<Double> summary, List<Double> outliers,
        List<String> additionalArgs) throws Exception {

    String plotTitle = "Combined Chart";
    String userTitle = getOption(additionalArgs, "-title");
    plotTitle = (userTitle != null) ? userTitle : plotTitle;

    List<String> opts = new ArrayList<String>();
    opts.add("-title=histogram");
    BufferedImage hist = renderHistogramFromSummaryData(width / 2, height, bins, freqs, opts);
    opts.clear();
    opts.add("-title=box plot");
    BufferedImage box = null;
    try {
        box = renderBoxPlotFromSummaryData(width / 2, height, summary, outliers, opts);
    } catch (Exception ex) {
        // if we can't generate the box plot (i.e. probably because
        // data is 100% missing) then just return the histogram
    }

    if (box == null) {
        width /= 2;
    }
    BufferedImage img = new BufferedImage(width, height + 20, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2d = img.createGraphics();
    g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
    g2d.setFont(new Font("SansSerif", Font.BOLD, 12));
    g2d.setColor(Color.lightGray);
    g2d.fillRect(0, 0, width, height + 20);
    g2d.setColor(Color.black);
    FontMetrics fm = g2d.getFontMetrics();
    int fh = fm.getHeight();
    int sw = fm.stringWidth(plotTitle);

    if (box != null) {
        g2d.drawImage(box, 0, 20, null);
        g2d.drawImage(hist, width / 2 + 1, 20, null);
    } else {
        g2d.drawImage(hist, 0, 20, null);
    }
    g2d.drawString(plotTitle, width / 2 - sw / 2, fh + 2);
    g2d.dispose();

    return img;
}

From source file:org.codice.alliance.imaging.chip.transformer.CatalogOutputAdapter.java

private void setImageDataFields(BufferedImage chip, ImageSegment chipImageSegment) throws IOException {

    int[] componentSizes = chip.getColorModel().getComponentSize();
    int pixelSize = chip.getColorModel().getPixelSize();

    switch (chip.getType()) {
    case BufferedImage.TYPE_BYTE_GRAY:
    case BufferedImage.TYPE_USHORT_GRAY:
    case BufferedImage.TYPE_BYTE_BINARY:
        setMonochrome(chipImageSegment, componentSizes[0], pixelSize);
        break;//w  w  w.  java  2 s.  c om
    case BufferedImage.TYPE_3BYTE_BGR:
    case BufferedImage.TYPE_INT_BGR:
        setImageFieldHelper(chipImageSegment, PixelValueType.INTEGER, ImageRepresentation.RGBTRUECOLOUR,
                componentSizes[0], pixelSize / 3, new String[] { "B", "G", "R" });
        break;
    case BufferedImage.TYPE_4BYTE_ABGR:
    case BufferedImage.TYPE_4BYTE_ABGR_PRE:
        setImageFieldHelper(chipImageSegment, PixelValueType.INTEGER, ImageRepresentation.RGBTRUECOLOUR,
                componentSizes[0], pixelSize / 4, new String[] { "B", "G", "R" });
        break;
    case BufferedImage.TYPE_INT_ARGB_PRE:
    case BufferedImage.TYPE_INT_ARGB:
        setARGB(chipImageSegment, componentSizes[0], pixelSize);
        break;
    case BufferedImage.TYPE_INT_RGB:
    case BufferedImage.TYPE_USHORT_555_RGB:
        setRGB(chipImageSegment, componentSizes[0], pixelSize);
        break;
    case BufferedImage.TYPE_CUSTOM:
        if (componentSizes.length == 1) {
            setMonochrome(chipImageSegment, componentSizes[0], pixelSize);
        } else if (componentSizes.length == 3) {
            setRGB(chipImageSegment, componentSizes[0], pixelSize);
        } else if (componentSizes.length == 4) {
            setARGB(chipImageSegment, componentSizes[0], pixelSize);
        } else {
            throw new IOException(
                    "unsupported color model for image type CUSTOM, only monochrome and 32-bit argb are supported");
        }
        break;
    case BufferedImage.TYPE_BYTE_INDEXED:
        setImageFieldHelper(chipImageSegment, PixelValueType.INTEGER, ImageRepresentation.RGBLUT,
                componentSizes[0], pixelSize, new String[] { "LU" });
        break;
    case BufferedImage.TYPE_USHORT_565_RGB:
        // don't know how to handle this one, since the bitsPerPixelPerBand is not consistent
        break;
    default:
        throw new IOException("unsupported image data type: type=" + chip.getType());
    }
}

From source file:eu.udig.style.advanced.utils.Utilities.java

/**
 * Creates an image from a set of {@link RuleWrapper}s.
 * /*ww  w  . j  av  a  2  s  . c o m*/
 * @param rulesWrapperList the list of rules wrapper.
 * @param width the image width.
 * @param height the image height.
 * @return the new created {@link BufferedImage}.
 */
public static BufferedImage lineRulesWrapperToImage(final List<RuleWrapper> rulesWrapperList, int width,
        int height) {
    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2d = image.createGraphics();
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    for (RuleWrapper rule : rulesWrapperList) {
        BufferedImage tmpImage = Utilities.lineRuleWrapperToImage(rule, width, height);
        g2d.drawImage(tmpImage, 0, 0, null);
    }
    g2d.dispose();
    return image;
}

From source file:com.codename1.android.AndroidLayoutImporter.java

private EncodedImage createBlankImage(String widthStr, String heightStr) {
    String name = "BlankImage";
    int width = convertToPixels(widthStr);
    if (width < 1)
        width = 1;/*from w ww  .  j  a v  a  2 s . c o  m*/
    int height = convertToPixels(heightStr);
    if (height < 1) {
        height = 1;
    }
    //System.out.println("Creating blank image "+width+"x"+height+" for "+widthStr+"x"+heightStr);
    String imgName = name + width + "x" + height + ".png";
    Image im = outputResources.getImage(imgName);
    if (im != null) {
        if (im instanceof EncodedImage) {
            return (EncodedImage) im;
        } else {
            return EncodedImage.createFromImage(im, false);
        }
    }
    BufferedImage center = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = (Graphics2D) center.createGraphics();
    //g2.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR));
    g2.setColor(Color.red);
    g2.fillRect(0, 0, width, height);
    g2.dispose();

    EncodedImage placeholder = EncodedImage.create(toPng(center));

    EditableResources.MultiImage multiImage = new EditableResources.MultiImage();
    multiImage.setDpi(new int[] { Display.DENSITY_MEDIUM });
    multiImage.setInternalImages(new EncodedImage[] { placeholder });

    outputResources.setMultiImage(imgName, multiImage);
    return multiImage.getBest();
}

From source file:de.bund.bfr.knime.gis.views.canvas.CanvasUtils.java

public static Paint mixColors(Color backgroundColor, List<Color> colors, List<Double> alphas,
        boolean checkedInsteadOfStriped) {
    double rb = backgroundColor.getRed() / 255.0;
    double gb = backgroundColor.getGreen() / 255.0;
    double bb = backgroundColor.getBlue() / 255.0;
    double ab = backgroundColor.getAlpha() / 255.0;
    List<Color> cs = new ArrayList<>();

    for (int i = 0; i < colors.size(); i++) {
        double alpha = alphas.get(i);

        if (alpha > 0.0) {
            double r = colors.get(i).getRed() / 255.0 * alpha + rb * (1 - alpha);
            double g = colors.get(i).getGreen() / 255.0 * alpha + gb * (1 - alpha);
            double b = colors.get(i).getBlue() / 255.0 * alpha + bb * (1 - alpha);
            double a = colors.get(i).getAlpha() / 255.0 * alpha + ab * (1 - alpha);

            cs.add(new Color((float) r, (float) g, (float) b, (float) a));
        }//  ww w  .j  a v  a  2  s.  c o m
    }

    if (cs.isEmpty()) {
        return backgroundColor;
    } else if (cs.size() == 1) {
        return cs.get(0);
    }

    BufferedImage img;
    int size = cs.size() * (checkedInsteadOfStriped ? EDGE_TEXTURE_SIZE : NODE_TEXTURE_SIZE);

    if (checkedInsteadOfStriped) {
        img = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);

        for (int x = 0; x < size; x++) {
            for (int y = 0; y < size; y++) {
                img.setRGB(x, y, cs.get((x / EDGE_TEXTURE_SIZE + y / EDGE_TEXTURE_SIZE) % cs.size()).getRGB());
            }
        }
    } else {
        img = new BufferedImage(size, 1, BufferedImage.TYPE_INT_ARGB);

        for (int x = 0; x < size; x++) {
            img.setRGB(x, 0, cs.get(x / NODE_TEXTURE_SIZE).getRGB());
        }
    }

    return new TexturePaint(img, new Rectangle(img.getWidth(), img.getHeight()));
}

From source file:com.ricemap.spateDB.operations.Plot.java

public static <S extends Shape> void plotLocal(Path inFile, Path outFile, S shape, int width, int height,
        Color color, boolean showBorders, boolean showBlockCount, boolean showRecordCount) throws IOException {
    FileSystem inFs = inFile.getFileSystem(new Configuration());
    Prism fileMbr = FileMBR.fileMBRLocal(inFs, inFile, shape);
    LOG.info("FileMBR: " + fileMbr);

    // Adjust width and height to maintain aspect ratio
    if ((fileMbr.x2 - fileMbr.x1) / (fileMbr.y2 - fileMbr.y1) > (double) width / height) {
        // Fix width and change height
        height = (int) ((fileMbr.y2 - fileMbr.y1) * width / (fileMbr.x2 - fileMbr.x1));
    } else {/*from  ww  w  .ja v  a  2  s.co m*/
        width = (int) ((fileMbr.x2 - fileMbr.x1) * height / (fileMbr.y2 - fileMbr.y1));
    }

    double scale2 = (double) width * height / ((double) (fileMbr.x2 - fileMbr.x1) * (fileMbr.y2 - fileMbr.y1));

    // Create an image
    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D graphics = image.createGraphics();
    Color bg_color = new Color(0, 0, 0, 0);
    graphics.setBackground(bg_color);
    graphics.clearRect(0, 0, width, height);
    graphics.setColor(color);

    long fileLength = inFs.getFileStatus(inFile).getLen();
    ShapeRecordReader<S> reader = new ShapeRecordReader<S>(inFs.open(inFile), 0, fileLength);

    Prism cell = reader.createKey();
    while (reader.next(cell, shape)) {
        drawShape(graphics, shape, fileMbr, width, height, scale2);
    }

    reader.close();
    graphics.dispose();
    FileSystem outFs = outFile.getFileSystem(new Configuration());
    OutputStream out = outFs.create(outFile, true);
    ImageIO.write(image, "png", out);
    out.close();
}

From source file:peakml.math.Signal.java

public BufferedImage createGraphImage(String name, String xlabel, String ylabel, int width, int height) {
    JFreeChart linechart = createGraph(name, xlabel, ylabel);

    // create the image
    BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    // create the graphics context
    Graphics2D g = img.createGraphics();

    // draw the line chart
    linechart.draw(g, new Rectangle(0, 0, width, height));

    // return the result
    return img;/*from   www.  j a  v a  2  s  .c o m*/
}

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

/**
 * @param book//w w  w .  j ava2 s. co  m
 * @param category
 * @return
 * @throws Exception
 */
public String createDefaultBackCoverEncoded(Book book, BookCover cover, BookCategory category)
        throws Exception {
    return createBackCoverEncoded(book.getCoverName(), book.getBookTitle(), category.getColor(),
            cover.getCoverTitleTextColor(), 300, 400, BufferedImage.TYPE_INT_ARGB, ImageFormat.IMAGE_FORMAT_PNG,
            128);
}