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:ddf.catalog.transformer.OverlayMetacardTransformer.java

private static BufferedImage createImage(BufferedImage original, List<Vector> boundary, int width, int height) {
    BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

    int[] xs = new int[4];
    int[] ys = new int[4];
    for (int i = 0; i < boundary.size(); i++) {
        xs[i] = (int) boundary.get(i).get(0);
        ys[i] = (int) -boundary.get(i).get(1);
    }/*from  w  w  w. j a  v a 2s. c o  m*/

    // We have a rectangular image and we have boundary points that the image should
    // be in. This transform moves the corners of the image to be at those boundary points.
    PerspectiveFilter perspectiveFilter = new PerspectiveFilter();
    perspectiveFilter.setCorners(xs[0], ys[0], xs[1], ys[1], xs[2], ys[2], xs[3], ys[3]);
    img = perspectiveFilter.filter(original, img);

    return img;
}

From source file:org.apache.fop.visual.BitmapComparator.java

/**
 * Loads an image from a URL//from  www.  j av a 2 s  .  c o m
 * @param url the URL to the image
 * @return the bitmap as BufferedImage
 * TODO This method doesn't close the InputStream opened by the URL.
 */
public static BufferedImage getImage(URL url) {
    ImageTagRegistry reg = ImageTagRegistry.getRegistry();
    Filter filt = reg.readURL(new ParsedURL(url));
    if (filt == null) {
        return null;
    }

    RenderedImage red = filt.createDefaultRendering();
    if (red == null) {
        return null;
    }

    BufferedImage img = new BufferedImage(red.getWidth(), red.getHeight(), BufferedImage.TYPE_INT_ARGB);
    red.copyData(img.getRaster());

    return img;
}

From source file:iqq.app.ui.manager.MainManager.java

public void enableTray() {
    if (SystemTray.isSupported() && tray == null) {
        menu = new PopupMenu();
        MenuItem restore = new MenuItem("  ?  ");
        restore.addActionListener(new ActionListener() {
            @Override/*from www .ja va2s  . c o m*/
            public void actionPerformed(ActionEvent e) {
                show();
            }
        });
        MenuItem exit = new MenuItem("  ?  ");
        exit.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        });
        menu.add(restore);
        menu.addSeparator();
        menu.add(exit);

        if (SystemUtils.isMac()) {
            defaultImage = skinService.getIconByKey("window/titleWIconBlack").getImage();
        } else {
            defaultImage = mainFrame.getIconImage();
        }
        blankImage = new BufferedImage(32, 32, BufferedImage.TYPE_INT_ARGB);
        tray = SystemTray.getSystemTray();
        icon = new TrayIcon(defaultImage, "IQQ");
        icon.setImageAutoSize(true);
        if (!SystemUtils.isMac()) {
            icon.setPopupMenu(menu);
        }
        try {
            tray.add(icon);
            icon.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    logger.debug("MouseEvent " + e.getButton() + " " + e.getClickCount());
                    //??
                    if (e.getButton() == MouseEvent.BUTTON1) {
                        if (flashOwner != null) {
                            Map<String, Object> data = (Map<String, Object>) flashOwner.getAttachment();
                            if (data != null && data.containsKey("action")
                                    && data.get("action").equals("ADD_BUDDY_REQUEST")) {
                                IMContext.getBean(FrameManager.class).showGetFriendRequest((IMBuddy) flashOwner,
                                        data.get("buddy_request_id").toString());
                                eventService.broadcast(new UIEvent(UIEventType.FLASH_USER_STOP, flashOwner));
                                return;
                            } else {
                                // ?
                                chatManager.addChat(flashOwner);
                            }
                        } else {
                            show();
                        }
                    }
                }
            });
        } catch (AWTException e) {
            logger.error("SystemTray add icon.", e);
        }
    }

}

From source file:bachelorthesis.captchapreviewer.domain.ObservableCaptchaBuilder.java

@Override
public void notifyObeservers() {
    BufferedImage image = new BufferedImage(builder.getWidth(), builder.getHeight(),
            BufferedImage.TYPE_INT_ARGB);
    String answer = "";

    if (valid) {// w  w  w .  j a v  a2  s  .  c om
        try {
            Captcha c = builder.buildCaptcha();
            image = c.getImage();
            answer = c.getAnswer();
        } catch (ParseException ex) {
            Logger.getLogger(ObservableCaptchaBuilder.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    CaptchaDAO dao = new CaptchaDAO(image, answer, message);

    for (IObserver<CaptchaDAO> observer : observers) {
        observer.update(dao);
    }
}

From source file:org.jhotdraw.samples.svg.figures.SVGImage.java

public static SVGImage getLoadingImage() {
    BufferedImage image;/*from  w w w.jav  a 2s .c om*/
    try {
        image = ImageIO.read(SVGImage.class.getResource("loading.jpg"));
    } catch (Exception e) {
        String text = "";
        Font font = new Font("", Font.PLAIN, 18);
        image = new BufferedImage(150, 100, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g = (Graphics2D) image.createGraphics();
        g.setColor(Color.black);
        g.setFont(font);
        int w = g.getFontMetrics().stringWidth(text);
        int h = g.getFontMetrics().getHeight();
        g.drawString(text, 10, h);
        g.dispose();
    }
    return new SVGImage(image);
}

From source file:org.flowerplatform.util.servlet.ImageComposerServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    String requestedFile = request.getPathInfo();
    if (requestedFile.startsWith(UtilConstants.IMAGE_COMPOSER_PATH_PREFIX)) {
        requestedFile = requestedFile.substring(UtilConstants.IMAGE_COMPOSER_PATH_PREFIX.length());
    }/*from  ww w.j  a va  2  s .  c om*/

    String mapValue = null;
    String mapKey;
    if (useFilesFromTemporaryDirectory) {
        mapKey = requestedFile.intern();
    } else {
        // we don't need synchronization if useFilesFromTempProperty is false (so we don't use .intern)
        mapKey = requestedFile;
    }

    synchronized (mapKey) {
        if (useFilesFromTemporaryDirectory) {
            mapValue = tempFilesMap.get(requestedFile);
            if (mapValue != null) {
                if (getTempFile(mapValue).exists()) {
                    InputStream result = new FileInputStream(getTempFilePath(mapValue));
                    OutputStream output = response.getOutputStream();
                    IOUtils.copy(result, output);
                    logger.debug("File {} served from temp", mapValue);
                    result.close();
                    output.close();
                    return;
                } else { // the temporary file was deleted from disk. 
                    logger.debug("File {} found to be missing from temp", mapValue);
                }
            } else {
                synchronized (this) {
                    counter++;
                    mapValue = counter + "";
                    tempFilesMap.put(requestedFile, mapValue);
                    logger.debug("mapValue {} added", mapValue);
                }
            }
        }

        int indexOfSecondSlash = requestedFile.indexOf('/', 1); // 1, i.e. skip the first index
        if (indexOfSecondSlash < 0) {
            send404(request, response);
            return;
        }
        String[] paths = requestedFile.split("\\" + UtilConstants.RESOURCE_PATH_SEPARATOR);

        int width = 0;
        int height = 0;
        List<BufferedImage> images = new ArrayList<BufferedImage>();

        for (String path : paths) {
            if (!path.startsWith("/")) {
                path = "/" + path;
            }
            indexOfSecondSlash = path.indexOf('/', 1);
            String plugin = path.substring(0, indexOfSecondSlash);
            path = path.substring(indexOfSecondSlash);
            requestedFile = "platform:/plugin" + plugin + "/" + UtilConstants.PUBLIC_RESOURCES_DIR + path;
            try {
                URL url = new URL(requestedFile);
                BufferedImage image = ImageIO.read(url);
                images.add(image);
                if (width < image.getWidth()) {
                    width = image.getWidth();
                }
                if (height < image.getHeight()) {
                    height = image.getHeight();
                }
            } catch (Exception e) {
                // one of the images was not found; skip it
            }
        }

        BufferedImage result = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
        Graphics2D graphics = result.createGraphics();
        for (BufferedImage image : images) {
            graphics.drawImage(image, null, 0, 0);
        }
        graphics.dispose();
        // write image into the Temp folder
        if (!UtilConstants.TEMP_FOLDER.exists()) {
            UtilConstants.TEMP_FOLDER.mkdir();
        }

        FileOutputStream tempOutput = null;
        if (useFilesFromTemporaryDirectory) {
            tempOutput = new FileOutputStream(getTempFilePath(mapValue));
        }
        OutputStream output = response.getOutputStream();

        try {
            if (tempOutput != null) {
                ImageIO.write(result, "png", tempOutput);
                logger.debug("file {} written in temp", mapValue);
            }
            ImageIO.write(result, "png", output);
        } finally {
            if (tempOutput != null) {
                tempOutput.close();
            }
            output.close();
        }
    }
}

From source file:com.jaeksoft.searchlib.util.ImageUtils.java

public final static BufferedImage reduceImage(BufferedImage image, int width, int height) {
    int type = (image.getTransparency() == Transparency.OPAQUE) ? BufferedImage.TYPE_INT_RGB
            : BufferedImage.TYPE_INT_ARGB;
    BufferedImage ret = (BufferedImage) image;
    int w = image.getWidth();
    int h = image.getHeight();

    while (w != width || h != height) {
        if (w > width) {
            w /= 2;//from  w ww  .  jav  a 2  s.  com
            if (w < width)
                w = width;
        }

        if (h > height) {
            h /= 2;
            if (h < height)
                h = height;
        }

        BufferedImage tmp = new BufferedImage(w, h, type);

        Graphics2D g2 = tmp.createGraphics();
        g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
        g2.drawImage(ret, 0, 0, w, h, null);
        g2.dispose();
        ret = tmp;
    }
    return ret;
}

From source file:com.hmsinc.epicenter.spatial.render.SpatialScanRenderer.java

/**
 * @param context//www  .j av a  2s  . co m
 * @return
 */
private BufferedImage renderImage(final MapContext context, int width, int height) {

    logger.trace("Image width: {}  height: {}", width, height);

    final BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

    final Graphics2D graphics2D = (Graphics2D) image.getGraphics();

    final GTRenderer renderer = new StreamingRenderer();
    final RenderingHints h = new RenderingHints(RenderingHints.KEY_INTERPOLATION,
            RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    h.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    h.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    h.put(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
    h.put(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE);
    renderer.setJava2DHints(h);
    renderer.setContext(context);
    renderer.paint(graphics2D, new Rectangle(width, height), context.getAreaOfInterest());

    return image;
}

From source file:net.sf.mzmine.modules.visualization.twod.TwoDXYPlot.java

public boolean render(final Graphics2D g2, final Rectangle2D dataArea, int index, PlotRenderingInfo info,
        CrosshairState crosshairState) {

    // if this is not TwoDDataSet
    if (index != 0)
        return super.render(g2, dataArea, index, info, crosshairState);

    // prepare some necessary constants
    final int x = (int) dataArea.getX();
    final int y = (int) dataArea.getY();
    final int width = (int) dataArea.getWidth();
    final int height = (int) dataArea.getHeight();

    final double imageRTMin = (double) getDomainAxis().getRange().getLowerBound();
    final double imageRTMax = (double) getDomainAxis().getRange().getUpperBound();
    final double imageRTStep = (imageRTMax - imageRTMin) / width;
    final double imageMZMin = (double) getRangeAxis().getRange().getLowerBound();
    final double imageMZMax = (double) getRangeAxis().getRange().getUpperBound();
    final double imageMZStep = (imageMZMax - imageMZMin) / height;

    if ((zoomOutBitmap != null) && (imageRTMin == totalRTRange.getMin())
            && (imageRTMax == totalRTRange.getMax()) && (imageMZMin == totalMZRange.getMin())
            && (imageMZMax == totalMZRange.getMax()) && (zoomOutBitmap.getWidth() == width)
            && (zoomOutBitmap.getHeight() == height)) {
        g2.drawImage(zoomOutBitmap, x, y, null);
        return true;
    }/*ww w.  j  av a2 s .c o  m*/

    // Save current time
    Date renderStartTime = new Date();

    // prepare a double array of summed intensities
    double values[][] = new double[width][height];
    maxValue = 0; // now this is an instance variable
    Random r = new Random();

    for (int i = 0; i < width; i++)
        for (int j = 0; j < height; j++) {

            double pointRTMin = imageRTMin + (i * imageRTStep);
            double pointRTMax = pointRTMin + imageRTStep;
            double pointMZMin = imageMZMin + (j * imageMZStep);
            double pointMZMax = pointMZMin + imageMZStep;

            double lv = dataset.getMaxIntensity(new Range(pointRTMin, pointRTMax),
                    new Range(pointMZMin, pointMZMax), plotMode);

            if (logScale) {
                lv = Math.log10(lv);
                if (lv < 0 || Double.isInfinite(lv))
                    lv = 0;
                values[i][j] = lv;
                //values[r.nextInt(width)][r.nextInt(height)] = lv;
            } else {
                values[i][j] = lv;
            }

            if (lv > maxValue)
                maxValue = lv;

        }

    // This should never happen, but just for correctness
    if (maxValue == 0)
        return false;

    // Normalize all values
    for (int i = 0; i < width; i++)
        for (int j = 0; j < height; j++) {
            values[i][j] /= maxValue;
        }

    // prepare a bitmap of required size
    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

    // draw image points
    for (int i = 0; i < width; i++)
        for (int j = 0; j < height; j++) {
            Color pointColor = paletteType.getColor(values[i][j]);
            image.setRGB(i, height - j - 1, pointColor.getRGB());
        }

    // if we are zoomed out, save the values
    if ((imageRTMin == totalRTRange.getMin()) && (imageRTMax == totalRTRange.getMax())
            && (imageMZMin == totalMZRange.getMin()) && (imageMZMax == totalMZRange.getMax())) {
        zoomOutBitmap = image;
    }

    // Paint image
    g2.drawImage(image, x, y, null);

    Date renderFinishTime = new Date();

    logger.finest("Finished rendering 2D visualizer, "
            + (renderFinishTime.getTime() - renderStartTime.getTime()) + " ms");

    return true;

}

From source file:org.apache.flex.compiler.internal.embedding.transcoders.JPEGTranscoder.java

private byte[] bufferedImageToJPEG(ImageInfo imageInfo, int[] pixels) throws Exception {
    BufferedImage bufferedImage = new BufferedImage(imageInfo.width, imageInfo.height,
            BufferedImage.TYPE_INT_ARGB);
    bufferedImage.setRGB(0, 0, imageInfo.width, imageInfo.height, pixels, 0, imageInfo.width);

    ImageWriter writer = ImageIO.getImageWritersByFormatName("jpeg").next();
    ImageWriteParam writeParam = writer.getDefaultWriteParam();
    ColorModel colorModel = new DirectColorModel(24, 0x00ff0000, 0x0000ff00, 0x000000ff);
    ImageTypeSpecifier imageTypeSpecifier = new ImageTypeSpecifier(colorModel,
            colorModel.createCompatibleSampleModel(1, 1));
    writeParam.setDestinationType(imageTypeSpecifier);
    writeParam.setSourceBands(new int[] { 0, 1, 2 });
    writeParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);

    float q = 1.0f;
    if (quality != null)
        q = quality.floatValue();//  w ww .  ja  v  a 2s  .  com
    writeParam.setCompressionQuality(q);

    DAByteArrayOutputStream buffer = new DAByteArrayOutputStream();
    writer.setOutput(new MemoryCacheImageOutputStream(buffer));

    IIOImage ioImage = new IIOImage(bufferedImage, null, null);

    writer.write(null, ioImage, writeParam);
    writer.dispose();

    return buffer.getDirectByteArray();
}