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:org.apache.batik.transcoder.image.AbstractImageTranscoderTest.java

protected BufferedImage getImage(InputStream is) throws IOException {
    ImageTagRegistry reg = ImageTagRegistry.getRegistry();
    Filter filt = reg.readStream(is);
    if (filt == null)
        throw new IOException("Couldn't read Stream");

    RenderedImage red = filt.createDefaultRendering();
    if (red == null)
        throw new IOException("Couldn't render Stream");

    BufferedImage img = new BufferedImage(red.getWidth(), red.getHeight(), BufferedImage.TYPE_INT_ARGB);
    red.copyData(img.getRaster());//from   w w w.j  a  v a2s .com
    return img;
}

From source file:fr.ens.transcriptome.corsen.gui.qt.ResultGraphs.java

/**
 * Create a boxplot.//from ww w  .  j  a  va2 s  .  com
 * @param results Results to use
 * @return a QImage
 */
public QImage createBoxPlot(final CorsenResult results, final String unit) {

    this.width = this.width / 2;

    Map<Particle3D, Distance> distsMin = results.getMinDistances();
    Map<Particle3D, Distance> distsMax = results.getMaxDistances();

    if (distsMin == null || distsMax == null)
        return null;

    List<Float> listMin = new ArrayList<Float>();
    List<Float> listMax = new ArrayList<Float>();

    for (Map.Entry<Particle3D, Distance> e : distsMin.entrySet()) {

        final Particle3D p = e.getKey();

        final long intensity = p.getIntensity();
        final float distanceMin = e.getValue().getDistance();
        final float distanceMax = distsMax.get(p).getDistance();

        for (int i = 0; i < intensity; i++) {
            listMin.add(distanceMin);
            listMax.add(distanceMax);
        }
    }

    DefaultBoxAndWhiskerCategoryDataset defaultboxandwhiskercategorydataset = new DefaultBoxAndWhiskerCategoryDataset();

    if (results.getMinAnalyser().count() > 0)
        defaultboxandwhiskercategorydataset
                .add(convertDistanceAnalyserToBoxAndWhiskerItem(results.getMinAnalyser()), "Distances", "Min");

    // defaultboxandwhiskercategorydataset.add(listMin, "Distances", "Min");
    // defaultboxandwhiskercategorydataset.add(listMax, "Distances", "Max");

    JFreeChart chart = ChartFactory.createBoxAndWhiskerChart("Intensities Boxplot", "",
            "Distance" + unitLegend(unit), defaultboxandwhiskercategorydataset, false);

    addTransparency(chart);

    // CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
    // // chart.setBackgroundPaint(Color.white);
    // categoryplot.setBackgroundPaint(Color.lightGray);
    // categoryplot.setDomainGridlinePaint(Color.white);
    // categoryplot.setDomainGridlinesVisible(true);
    // categoryplot.setRangeGridlinePaint(Color.white);
    //
    // NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    // numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    final BufferedImage image = chart.createBufferedImage(this.width, this.height, BufferedImage.TYPE_INT_ARGB,
            null);

    return new QImage(toByte(image.getData().getDataBuffer()), this.width, this.height,
            QImage.Format.Format_ARGB32);
}

From source file:com.celements.photo.image.GenerateThumbnail.java

BufferedImage convertImageToBufferedImage(Image thumbImg, String watermark, String copyright, Color defaultBg) {
    BufferedImage thumb = new BufferedImage(thumbImg.getWidth(null), thumbImg.getHeight(null),
            BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2d = thumb.createGraphics();
    if (defaultBg != null) {
        g2d.setColor(defaultBg);/*from  w ww .  j a  v  a 2 s . co  m*/
        g2d.fillRect(0, 0, thumbImg.getWidth(null), thumbImg.getHeight(null));
    }
    g2d.drawImage(thumbImg, 0, 0, null);

    if ((watermark != null) && (!watermark.equals(""))) {
        drawWatermark(watermark, g2d, thumb.getWidth(), thumb.getHeight());
    }

    if ((copyright != null) && (!copyright.equals(""))) {
        drawCopyright(copyright, g2d, thumb.getWidth(), thumb.getHeight());
    }
    mLogger.info("thumbDimensions: " + thumb.getHeight() + "x" + thumb.getWidth());
    return thumb;
}

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

/**
 * Creates an {@link Image} for the given rule.
 * //from   w  ww  .j a v  a 2 s  . co m
 * @param rule the rule for which to create the image.
 * @param width the image width.
 * @param height the image height.
 * @return the generated image.
 */
public static BufferedImage pointRuleToImage(final Rule rule, int width, int height) {
    DuplicatingStyleVisitor copyStyle = new DuplicatingStyleVisitor();
    rule.accept(copyStyle);
    Rule newRule = (Rule) copyStyle.getCopy();

    int pointSize = 0;
    Stroke stroke = null;
    Symbolizer[] symbolizers = newRule.getSymbolizers();
    if (symbolizers.length > 0) {
        Symbolizer symbolizer = newRule.getSymbolizers()[0];
        if (symbolizer instanceof PointSymbolizer) {
            PointSymbolizer pointSymbolizer = (PointSymbolizer) symbolizer;
            pointSize = SLDs.pointSize(pointSymbolizer);
            stroke = SLDs.stroke(pointSymbolizer);
        }
    }
    int strokeSize = 0;
    if (stroke != null) {
        strokeSize = SLDs.width(stroke);
        if (strokeSize < 0) {
            strokeSize = 1;
            stroke.setWidth(ff.literal(strokeSize));
        }
    }
    pointSize = pointSize + 2 * strokeSize;
    if (pointSize <= 0) {
        pointSize = width;
    }

    // pointSize = width;
    BufferedImage finalImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    BufferedImage pointImage = new BufferedImage(pointSize, pointSize, BufferedImage.TYPE_INT_ARGB);
    Point point = d.point(pointSize / 2, pointSize / 2);
    d.drawDirect(pointImage, d.feature(point), newRule);
    Graphics2D g2d = finalImage.createGraphics();
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    if (pointSize > width || pointSize > height) {
        g2d.drawImage(pointImage, 0, 0, width, height, 0, 0, pointSize, pointSize, null);
    } else {
        int x = width / 2 - pointSize / 2;
        int y = height / 2 - pointSize / 2;
        g2d.drawImage(pointImage, x, y, null);
    }
    g2d.dispose();

    return finalImage;
}

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

/**
 * Creates a small front cover// ww  w  .  j a  va 2  s .c o  m
 * 
 * @param book
 * @param category
 * @param cover
 * @param logo
 * @param authorName
 * @return
 * @throws Exception
 */
public String createDefaultSmallFrontCoverEncoded(Book book, BookCategory category, BookCover cover,
        byte[] logo, String authorName) throws Exception {
    return createFrontCoverEncoded(book.getCoverName(), logo, authorName, book.getBookTitle(),
            category.getColor(), cover.getAuthorTextColor(), cover.getCoverTitleTextColor(), 75, 100,
            BufferedImage.TYPE_INT_ARGB, ImageFormat.IMAGE_FORMAT_PNG, 128);
}

From source file:edu.ku.brc.specify.utilapps.ERDTable.java

/**
 * Returns the BufferedImage of a background shadow. I creates a large rectangle than the orignal image.
 * @return Returns the BufferedImage of a background shadow. I creates a large rectangle than the orignal image.
 *///from  w w  w  .java2  s.com
private BufferedImage getBackgroundImageBuffer() {
    if (shadowBuffer == null) {
        ShadowFactory factory = new ShadowFactory(SHADOW_SIZE, 0.17f, Color.BLACK);

        Dimension size = inner.getSize();
        BufferedImage image = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_ARGB);

        Graphics2D g2 = image.createGraphics();
        g2.setColor(Color.WHITE);
        g2.fillRect(0, 0, image.getWidth(), image.getHeight());
        g2.dispose();

        shadowBuffer = factory.createShadow(image);
    }
    return shadowBuffer;
}

From source file:ded.ui.DiagramController.java

@Override
public void paint(Graphics g) {
    // Swing JPanel is double buffered already, but that is not
    // sufficient to avoid rendering bugs on Apple computers
    // with HiDPI/Retina displays.  This is an attempt at a
    // hack that might circumvent it, effectively triple-buffering
    // the rendering step.
    if (this.tripleBufferMode != 0) {
        // The idea here is if I create an in-memory image with no
        // initial association with the display, whatever hacks Apple
        // has added should not kick in, and I get unscaled pixel
        // rendering.
        BufferedImage bi;//from w w w.j a  v a 2s  .  c  o m

        if (this.tripleBufferMode == -1) {
            // This is not right because we might be drawing on a
            // different screen than the "default" screen.  Also, I
            // am worried that a "compatible" image might be one
            // subject to the scaling effects I'm trying to avoid.
            GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
            GraphicsConfiguration gc = gd.getDefaultConfiguration();
            bi = gc.createCompatibleImage(this.getWidth(), this.getHeight());
        } else {
            // This is not ideal because the color representation
            // for this hidden image may not match that of the display,
            // necessitating a conversion during 'drawImage'.
            try {
                bi = new BufferedImage(this.getWidth(), this.getHeight(), this.tripleBufferMode);
            } catch (IllegalArgumentException e) {
                // This would happen if 'tripleBufferMode' were invalid.
                if (this.tripleBufferMode == BufferedImage.TYPE_INT_ARGB) {
                    // I don't know how this could happen.  Re-throw.
                    this.log("creating a BufferedImage with TYPE_INT_ARGB failed: "
                            + Util.getExceptionMessage(e));
                    this.log("re-throwing exception...");
                    throw e;
                } else {
                    // Change it to something known to be valid and try again.
                    this.log("creating a BufferedImage with imageType " + this.tripleBufferMode + " failed: "
                            + Util.getExceptionMessage(e));
                    this.log("switching type to TYPE_INT_ARGB and re-trying...");
                    this.tripleBufferMode = BufferedImage.TYPE_INT_ARGB;
                    this.paint(g);
                    return;
                }
            }
        }
        Graphics g2 = bi.createGraphics();
        this.innerPaint(g2);
        g2.dispose();

        g.drawImage(bi, 0, 0, null /*imageObserver*/);
    } else {
        this.innerPaint(g);
    }

    if (this.fpsMeasurementMode) {
        // Immediately trigger another paint cycle.
        this.repaint();
    }
}

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

public void saveImages(String baseURL) {
    //System.out.println("sellitemimagecont: looking for image to upload!");
    //System.out.println("saving images :" + baseURL);
    baseURL = baseURL + "/" + GV.REMOTE_IMAGE_DIR + "/";

    // Special case for the thumbnail
    /*if(this.images.size()>1){
       FileItem image = this.images.get(0);
               /*from   w ww. j av  a  2  s.c  o m*/
       //TODO: compress an image
       String[] ext = image.getName().split("\\.");
       int extIndex = ext.length>0 ? ext.length-1 : 0;
       String filename = this.itemID + "_" + 0 + "." + ext[extIndex];
       String URL = filename;
               
       // Setup the thumbnail file
       File file = new File(GlobalVars.localImageDir, filename);
       file.setReadable(true, false);
       file.setWritable(true, false);
               
       try {
    image.write(file);
            
    GlobalVars.db.insertThumbnail(this.itemID, URL);
       } catch (Exception e) {
    // TODO Auto-generated catch block
    this.errors.add(new Error("SellItemImagesController (saveImages): Could not save thumbnail", e));
    e.printStackTrace();
       }
    }*/
    boolean thumbnail = true;

    // Loop through all the images
    for (int i = 0; i < this.images.size(); i++) {
        FileItem image = this.images.get(i);

        //TODO: make number start from one and only count real images

        if (image.getSize() > 0) {
            // Make the file name and path
            String[] ext = image.getName().split("\\.");
            int extIndex = ext.length > 0 ? ext.length - 1 : 0;
            String filename = this.itemID + "_" + (i + 1) + "." + ext[extIndex];
            //String URL = filename;

            // Setup the image file
            //System.out.println("setting temp dir as the image");
            File file = new File(GV.LOCAL_TEMP_DIR, filename + "tmp");
            file.setReadable(true, false);
            file.setWritable(true, false);

            //System.out.println("URL :" + URL);
            //System.out.println("name :" + filename);
            //System.out.println("local :" + GV.LOCAL_IMAGE_DIR);
            //System.out.println("remote :" + GV.REMOTE_IMAGE_DIR);

            try {
                //System.out.println("doing db insert");
                GV.DB.insertImage(this.itemID, i + 1, filename, "");

                //System.out.println("saving image");
                image.write(file);

                //System.out.println("mkaing file in img dir");
                File file2 = new File(GV.LOCAL_IMAGE_DIR, filename);

                //System.out.println("doing the image resize");
                BufferedImage originalImage2 = ImageIO.read(file);
                int type2 = originalImage2.getType() == 0 ? BufferedImage.TYPE_INT_ARGB
                        : originalImage2.getType();

                //System.out.println("doing the image resize second step");
                BufferedImage resizeImageHintJpg2 = resizeImageWithHint(originalImage2, type2, 500, 450);
                ImageIO.write(resizeImageHintJpg2, "jpg", file2);

                try {
                    file.delete();
                } catch (Exception e) {

                }

                //System.out.println("sellitemimagecont: inserted an image!");

                if (thumbnail) {
                    //TODO: some image compression
                    String thumbName = this.itemID + "_" + 0 + "." + ext[extIndex];
                    GV.DB.insertThumbnail(this.itemID, thumbName);

                    //System.out.println("doing thumbnail");

                    File thumbFile = new File(GV.LOCAL_IMAGE_DIR, thumbName);

                    // Get a JPEG writer
                    // TODO: other formats??
                    /*ImageWriter writer = null;
                      Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
                      if (iter.hasNext()) {
                          writer = (ImageWriter)iter.next();
                      }
                            
                      // Set the output file
                      ImageOutputStream ios = ImageIO.createImageOutputStream(thumbFile);
                      writer.setOutput(ios);
                              
                      // Set the compression level
                      JPEGImageWriteParam imgparams = new JPEGImageWriteParam(Locale.getDefault());
                      imgparams.setCompressionMode(ImageWriteParam.MODE_EXPLICIT) ;
                      imgparams.setCompressionQuality(128);
                              
                      // Write the compressed file
                      RenderedImage rendFile = ImageIO.read(file);
                      writer.write(null, new IIOImage(rendFile, null, null), imgparams);
                              
                              
                              
                            
                    // copy file
                    InputStream fin = new FileInputStream(file);
                    OutputStream fout = new FileOutputStream(thumbFile);
                    byte[] buff = new byte[1024];
                    int len;
                            
                    while((len = fin.read(buff)) > 0)
                         fout.write(buff, 0, len);
                            
                    fin.close();
                    fout.close();
                    */

                    BufferedImage originalImage = ImageIO.read(file2);
                    int type = originalImage.getType() == 0 ? BufferedImage.TYPE_INT_ARGB
                            : originalImage.getType();

                    BufferedImage resizeImageHintJpg = resizeImageWithHint(originalImage, type, 100, 100);
                    ImageIO.write(resizeImageHintJpg, "jpg", thumbFile);

                    thumbnail = false;
                }
            } catch (Exception e) {
                // TODO Auto-generated catch block
                this.errors.add(new Error("SellItemImagesController (saveImages): Could not save image", e));
                e.printStackTrace();
            }
        }
    }

    if (this.errors.size() == 0 && !this.useHTML5()) {
        createRedirectURL();
    }

    // Try to save the uploaded files
    /*try {
               
       while(images.hasNext()) {
    FileItem item = (FileItem) images.next();
    System.out.println("doing item 1");
    /*
     * Handle Form Fields.
     *
    if(item.isFormField()) {
       System.out.println("File Name = "+item.getFieldName()+", Value = "+item.getString());
    } else {
       //Handle Uploaded files.
       System.out.println("Field Name = "+item.getFieldName()+
          ", File Name = "+item.getName()+
          ", Content type = "+item.getContentType()+
          ", File Size = "+item.getSize());
       /*
        * Write file to the ultimate location.
        *
       File file = new File(GlobalVars.imageDir,item.getName());
       item.write(file);
    }
    //System.out.close();
       }
    }catch(Exception ex) {
       System.out.println("Error encountered while uploading file");
    }*/
}

From source file:de.mprengemann.intellij.plugin.androidicons.util.ImageUtils.java

private static BufferedImage rescaleBorder(BufferedImage image, int targetWidth, int targetHeight)
        throws IOException {
    if (targetWidth == 0) {
        targetWidth = 1;//ww w.  j  a va2s.  co m
    }
    if (targetHeight == 0) {
        targetHeight = 1;
    }

    if (targetHeight > 1 && targetWidth > 1) {
        throw new IOException();
    }

    int w = image.getWidth();
    int h = image.getHeight();
    int[] data = image.getRGB(0, 0, w, h, null, 0, w);
    int[] newData = new int[targetWidth * targetHeight];

    for (int x = 0; x < w; x++) {
        for (int y = 0; y < h; y++) {
            newData[y * targetWidth + x] = 0x00;
        }
    }

    List<Integer> startPositions = new ArrayList<Integer>();
    List<Integer> endPositions = new ArrayList<Integer>();

    boolean inBlock = false;
    if (targetHeight == 1) {
        for (int x = 0; x < w; x++) {
            if ((0xff000000 & data[x]) != 0) {
                if (!inBlock) {
                    inBlock = true;
                    startPositions.add(x);
                }
            } else if (inBlock) {
                endPositions.add(x - 1);
                inBlock = false;
            }
        }
        if (inBlock) {
            endPositions.add(w - 1);
        }
    } else {
        for (int y = 0; y < h; y++) {
            if ((0xff000000 & data[y]) != 0) {
                if (!inBlock) {
                    inBlock = true;
                    startPositions.add(y);
                }
            } else if (inBlock) {
                endPositions.add(y - 1);
                inBlock = false;
            }
        }
        if (inBlock) {
            endPositions.add(h - 1);
        }
    }
    try {
        SplineInterpolator interpolator = new SplineInterpolator();
        PolynomialSplineFunction function = interpolator.interpolate(
                new double[] { 0f, 1f, Math.max(w - 1, h - 1) },
                new double[] { 0f, 1f, Math.max(targetHeight - 1, targetWidth - 1) });
        for (int i = 0; i < startPositions.size(); i++) {
            int start = startPositions.get(i);
            int end = endPositions.get(i);
            for (int j = (int) function.value(start); j <= (int) function.value(end); j++) {
                newData[j] = 0xff000000;
            }
        }

        BufferedImage img = UIUtil.createImage(targetWidth, targetHeight, BufferedImage.TYPE_INT_ARGB);
        img.setRGB(0, 0, targetWidth, targetHeight, newData, 0, targetWidth);
        return img;
    } catch (Exception e) {
        Logger.getInstance(ImageUtils.class).error("resizeBorder", e);
    }

    return null;
}

From source file:PrintCanvas3D.java

BufferedImage doRender(int width, int height) {

    BufferedImage bImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

    ImageComponent2D buffer = new ImageComponent2D(ImageComponent.FORMAT_RGBA, bImage);

    setOffScreenBuffer(buffer);/*from  w  ww.ja va  2  s .c  o  m*/
    renderOffScreenBuffer();
    waitForOffScreenRendering();
    bImage = getOffScreenBuffer().getImage();

    return bImage;
}