Example usage for java.awt.image BufferedImage TYPE_INT_RGB

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

Introduction

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

Prototype

int TYPE_INT_RGB

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

Click Source Link

Document

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

Usage

From source file:org.tsho.dmc2.core.chart.AbsorbingAreaRenderer.java

public void render(final Graphics2D g2, final Rectangle2D dataArea, final PlotRenderingInfo info) {

    state = STATE_RUNNING;/* w w w.  j  av a  2 s.co  m*/

    gridWidth = (int) dataArea.getWidth();
    gridHeight = (int) dataArea.getHeight();

    //imageX,imageY correspond to point(0,0)
    int imageX = (int) dataArea.getX() + 1;
    int imageY = (int) dataArea.getY() + 1;

    DataBufferInt dataBuffer;

    image = new BufferedImage(gridWidth, gridHeight, BufferedImage.TYPE_INT_RGB);
    WritableRaster raster = image.getRaster();
    grid = ((DataBufferInt) raster.getDataBuffer()).getData();

    ValueAxis domainAxis = plot.getDomainAxis();
    ValueAxis rangeAxis = plot.getRangeAxis();

    xEpsilon = Math.abs((domainAxis.getUpperBound() - domainAxis.getLowerBound()) / (double) gridWidth);
    yEpsilon = Math.abs((rangeAxis.getUpperBound() - rangeAxis.getLowerBound()) / (double) gridHeight);

    int numPoints = gridHeight * gridWidth;
    int index = 0;
    int rate = numPoints / 100;

    if (justClearedSet) {
        if (criticalSetFound) {
            this.clearDisplay();
            g2.drawImage(image, null, imageX, imageY);
        }
        justClearedSet = false;
        return;
    }

    if (!notYetRendered) {
        plotCopiedDisplay();
        g2.drawImage(image, null, imageX, imageY);
    }
    notYetRendered = false;
    if (criticalSetFound && !findCriticalSetAgain) {
        if (this.chooseSegmentsSet)
            chooseSegments(g2, image, imageX, imageY);
        if (this.plotAttractorSet)
            plotAttractor(g2, image, imageX, imageY);
        if (this.iterateChosenSegmentsSet)
            iterateChosenSegments(g2, image, imageX, imageY);
        if (this.hideAttractorSet)
            hideAttractor(g2, image, imageX, imageY);
    } else {
        this.disableAllActionsExceptStop();
        det = new AbsorbingAreaRenderer.ImplicitDeterminant(gridWidth, gridHeight, epsilon, g2, image, imageX,
                imageY);
        gridBackup = new int[grid.length];
        copyDisplay();
        criticalSetFound = true;
        findCriticalSetAgain = false;
        g2.drawImage(image, null, imageX, imageY);
        this.enableAllActionsExceptStop();
    }
}

From source file:editeurpanovisu.ReadWriteImage.java

/**
 *
 * @param img//from   ww  w .jav  a  2s.c  om
 * @param destFile
 * @param quality
 * @param sharpen
 * @param sharpenLevel
 * @throws IOException
 */
public static void writeJpeg(Image img, String destFile, float quality, boolean sharpen, float sharpenLevel)
        throws IOException {
    sharpenMatrix = calculeSharpenMatrix(sharpenLevel);
    BufferedImage imageRGBSharpen = null;
    IIOImage iioImage = null;
    BufferedImage image = SwingFXUtils.fromFXImage(img, null); // Get buffered image.

    BufferedImage imageRGB = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.OPAQUE); // Remove alpha-channel from buffered image.

    Graphics2D graphics = imageRGB.createGraphics();
    graphics.drawImage(image, 0, 0, null);
    if (sharpen) {
        imageRGBSharpen = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_RGB);
        Kernel kernel = new Kernel(3, 3, sharpenMatrix);
        ConvolveOp cop = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null);
        cop.filter(imageRGB, imageRGBSharpen);
    }
    ImageWriter writer = null;
    FileImageOutputStream output = null;
    try {
        writer = ImageIO.getImageWritersByFormatName("jpeg").next();
        ImageWriteParam param = writer.getDefaultWriteParam();
        param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
        param.setCompressionQuality(quality);
        output = new FileImageOutputStream(new File(destFile));
        writer.setOutput(output);
        if (sharpen) {
            iioImage = new IIOImage(imageRGBSharpen, null, null);
        } else {
            iioImage = new IIOImage(imageRGB, null, null);
        }
        writer.write(null, iioImage, param);
    } catch (IOException ex) {
        throw ex;
    } finally {
        if (writer != null) {
            writer.dispose();
        }
        if (output != null) {
            output.close();
        }
    }
    graphics.dispose();
}

From source file:net.sf.dynamicreports.jasper.builder.JasperConcatenatedReportBuilder.java

public JasperConcatenatedReportBuilder toPng(OutputStream outputStream, float zoom) throws DRException {
    Validate.notNull(outputStream, "outputStream must not be null");
    Validate.isTrue(zoom > 0, "zoom must be > 0");

    int maxWidth = 0;
    int maxHeight = 0;

    for (JasperPrint jasperPrint : jasperReportHandler.getPrintList()) {
        int pages = jasperPrint.getPages().size();
        int pageWidth = (int) (jasperPrint.getPageWidth() * zoom);
        maxWidth += pageWidth * pages + (pages - 1) + 2;
        int height = (int) (jasperPrint.getPageHeight() * zoom) + 2;
        if (height > maxHeight) {
            maxHeight = height;//  ww  w. ja  v a 2  s  . c  o m
        }
    }

    Image pageImage = new BufferedImage(maxWidth, maxHeight, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2d = (Graphics2D) pageImage.getGraphics();
    g2d.setColor(Color.LIGHT_GRAY);
    g2d.fill(new Rectangle2D.Float(1, 1, maxWidth - 1, maxHeight - 1));

    int offset = 1;
    for (JasperPrint jasperPrint : jasperReportHandler.getPrintList()) {
        int pageWidth = (int) (jasperPrint.getPageWidth() * zoom);
        for (int i = 0; i < jasperPrint.getPages().size(); i++) {
            try {
                JRGraphics2DExporter exporter = new JRGraphics2DExporter();
                exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
                exporter.setParameter(JRGraphics2DExporterParameter.GRAPHICS_2D, pageImage.getGraphics());
                exporter.setParameter(JRGraphics2DExporterParameter.OFFSET_X, offset);
                exporter.setParameter(JRGraphics2DExporterParameter.OFFSET_Y, 1);
                exporter.setParameter(JRExporterParameter.PAGE_INDEX, new Integer(i));
                exporter.setParameter(JRGraphics2DExporterParameter.ZOOM_RATIO, new Float(zoom));
                exporter.exportReport();
                offset += pageWidth + 1;
            } catch (JRException e) {
                throw new DRException(e);
            }
        }
    }
    try {
        ImageIO.write((RenderedImage) pageImage, "png", outputStream);
    } catch (IOException e) {
        throw new DRException(e);
    }
    return this;
}

From source file:org.spf4j.perf.impl.chart.Charts.java

public static BufferedImage generateCountTotalChart(final String groupName, final long[][] timestamps,
        final String[] measurementNames, final String uom1, final double[][] measurements, final int width,
        final int height, final String[] measurementNames2, final String uom2, final double[][] measurements2) {
    BufferedImage count = Charts/*w  ww  .j a v  a 2s. c o m*/
            .createTimeSeriesJFreeChart("Measurements for " + groupName + " generated by spf4j", timestamps,
                    measurementNames, uom1, measurements)
            .createBufferedImage(width, height / 2);
    BufferedImage total = Charts
            .createTimeSeriesJFreeChart(null, timestamps, measurementNames2, uom2, measurements2)
            .createBufferedImage(width, height / 2);
    BufferedImage combined = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    final Graphics graphics = combined.getGraphics();
    try {
        graphics.drawImage(count, 0, 0, null);
        graphics.drawImage(total, 0, height / 2, null);
    } finally {
        graphics.dispose();
    }
    return combined;
}

From source file:iqq.util.ImageUtil.java

/**
 * /* www. ja v  a  2s .c o  m*/
 *
 * @param srcFile ?
 * @param destFile 
 * @param destWidth 
 * @param destHeight 
 */
public static void zoom(File srcFile, File destFile, int destWidth, int destHeight) {
    if (type == Type.jdk) {
        try {
            BufferedImage srcBufferedImage = ImageIO.read(srcFile);
            int srcWidth = srcBufferedImage.getWidth();
            int srcHeight = srcBufferedImage.getHeight();
            int width = destWidth;
            int height = destHeight;
            if (srcHeight >= srcWidth) {
                width = (int) Math.round(((destHeight * 1.0 / srcHeight) * srcWidth));
            } else {
                height = (int) Math.round(((destWidth * 1.0 / srcWidth) * srcHeight));
            }
            BufferedImage destBufferedImage = new BufferedImage(destWidth, destHeight,
                    BufferedImage.TYPE_INT_RGB);
            Graphics2D graphics2D = destBufferedImage.createGraphics();
            graphics2D.setBackground(BACKGROUND_COLOR);
            graphics2D.clearRect(0, 0, destWidth, destHeight);
            graphics2D.drawImage(srcBufferedImage.getScaledInstance(width, height, Image.SCALE_SMOOTH),
                    (destWidth / 2) - (width / 2), (destHeight / 2) - (height / 2), null);
            graphics2D.dispose();

            FileOutputStream out = new FileOutputStream(destFile);
            JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
            JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(destBufferedImage);
            param.setQuality((float) DEST_QUALITY / 100, false);
            encoder.setJPEGEncodeParam(param);
            encoder.encode(destBufferedImage);
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } else {
        IMOperation operation = new IMOperation();
        operation.thumbnail(destWidth, destHeight);
        operation.gravity("center");
        operation.background(toHexEncoding(BACKGROUND_COLOR));
        operation.extent(destWidth, destHeight);
        operation.quality((double) DEST_QUALITY);
        operation.addImage(srcFile.getPath());
        operation.addImage(destFile.getPath());
        if (type == Type.graphicsMagick) {
            ConvertCmd convertCmd = new ConvertCmd(true);
            if (graphicsMagickPath != null) {
                convertCmd.setSearchPath(graphicsMagickPath);
            }
            try {
                convertCmd.run(operation);
            } catch (IOException e) {
                e.printStackTrace();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (IM4JavaException e) {
                e.printStackTrace();
            }
        } else {
            ConvertCmd convertCmd = new ConvertCmd(false);
            if (imageMagickPath != null) {
                convertCmd.setSearchPath(imageMagickPath);
            }
            try {
                convertCmd.run(operation);
            } catch (IOException e) {
                e.printStackTrace();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (IM4JavaException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:ScaleTest_2008.java

/**
 * Progressive bilinear scaling: for any downscale size, scale
 * iteratively by halves using BILINEAR filtering until the proper 
 * size is reached./*from  ww w.j  av  a  2s.  co  m*/
 */
private BufferedImage getOptimalScalingImage(BufferedImage inputImage, int startSize, int endSize) {
    int currentSize = startSize;
    BufferedImage currentImage = inputImage;
    int delta = currentSize - endSize;
    int nextPow2 = currentSize >> 1;
    while (currentSize > 1) {
        if (delta <= nextPow2) {
            if (currentSize != endSize) {
                BufferedImage tmpImage = new BufferedImage(endSize, endSize, BufferedImage.TYPE_INT_RGB);
                Graphics g = tmpImage.getGraphics();
                ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                        RenderingHints.VALUE_INTERPOLATION_BILINEAR);
                g.drawImage(currentImage, 0, 0, tmpImage.getWidth(), tmpImage.getHeight(), null);
                currentImage = tmpImage;
            }
            return currentImage;
        } else {
            BufferedImage tmpImage = new BufferedImage(currentSize >> 1, currentSize >> 1,
                    BufferedImage.TYPE_INT_RGB);
            Graphics g = tmpImage.getGraphics();
            ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                    RenderingHints.VALUE_INTERPOLATION_BILINEAR);
            g.drawImage(currentImage, 0, 0, tmpImage.getWidth(), tmpImage.getHeight(), null);
            currentImage = tmpImage;
            currentSize = currentImage.getWidth();
            delta = currentSize - endSize;
            nextPow2 = currentSize >> 1;
        }
    }
    return currentImage;
}

From source file:net.shopxx.util.ImageUtil.java

/**
 * //ww  w.  j av  a2 s  . c  o  m
 * @param srcFile ?
 * @param destFile 
 * @param destWidth 
 * @param destHeight 
 */
public static void zoom(File srcFile, File destFile, int destWidth, int destHeight) {
    Assert.notNull(srcFile);
    Assert.notNull(destFile);
    Assert.state(destWidth > 0);
    Assert.state(destHeight > 0);
    if (type == Type.jdk) {
        try {
            BufferedImage srcBufferedImage = ImageIO.read(srcFile);
            int srcWidth = srcBufferedImage.getWidth();
            int srcHeight = srcBufferedImage.getHeight();
            int width = destWidth;
            int height = destHeight;
            if (srcHeight >= srcWidth) {
                width = (int) Math.round(((destHeight * 1.0 / srcHeight) * srcWidth));
            } else {
                height = (int) Math.round(((destWidth * 1.0 / srcWidth) * srcHeight));
            }
            BufferedImage destBufferedImage = new BufferedImage(destWidth, destHeight,
                    BufferedImage.TYPE_INT_RGB);
            Graphics2D graphics2D = destBufferedImage.createGraphics();
            graphics2D.setBackground(BACKGROUND_COLOR);
            graphics2D.clearRect(0, 0, destWidth, destHeight);
            graphics2D.drawImage(srcBufferedImage.getScaledInstance(width, height, Image.SCALE_SMOOTH),
                    (destWidth / 2) - (width / 2), (destHeight / 2) - (height / 2), null);
            graphics2D.dispose();

            FileOutputStream out = new FileOutputStream(destFile);
            JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
            JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(destBufferedImage);
            param.setQuality((float) DEST_QUALITY / 100, false);
            encoder.setJPEGEncodeParam(param);
            encoder.encode(destBufferedImage);
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } else {
        IMOperation operation = new IMOperation();
        operation.thumbnail(destWidth, destHeight);
        operation.gravity("center");
        operation.background(toHexEncoding(BACKGROUND_COLOR));
        operation.extent(destWidth, destHeight);
        operation.quality((double) DEST_QUALITY);
        operation.addImage(srcFile.getPath());
        operation.addImage(destFile.getPath());
        if (type == Type.graphicsMagick) {
            ConvertCmd convertCmd = new ConvertCmd(true);
            if (graphicsMagickPath != null) {
                convertCmd.setSearchPath(graphicsMagickPath);
            }
            try {
                convertCmd.run(operation);
            } catch (IOException e) {
                e.printStackTrace();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (IM4JavaException e) {
                e.printStackTrace();
            }
        } else {
            ConvertCmd convertCmd = new ConvertCmd(false);
            if (imageMagickPath != null) {
                convertCmd.setSearchPath(imageMagickPath);
            }
            try {
                convertCmd.run(operation);
            } catch (IOException e) {
                e.printStackTrace();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (IM4JavaException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:de.anycook.upload.UploadHandler.java

/**
 * speichert eine grosse Version des Bildes
 *
 * @param image    BufferedImage/*  w  w  w.j  a va2  s  .c  o  m*/
 * @param filename Name der zu erzeugenden Datei
 */
private void saveBigImage(BufferedImage image, String filename) throws IOException {
    int height = image.getHeight();
    int width = image.getWidth();

    int newWidth = bigWidth;
    int newHeight = new Double(((double) height / (double) width) * newWidth).intValue();

    if (bigHeight > -1 && newHeight > bigHeight) {
        newHeight = bigHeight;
        newWidth = new Double(((double) width / (double) height) * newHeight).intValue();
    }

    BufferedImage newImage = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_RGB);
    newImage.getGraphics().drawImage(image.getScaledInstance(newWidth, newHeight, Image.SCALE_SMOOTH), 0, 0,
            null);

    imageSaver.save("big/", filename, newImage);

}

From source file:CombineApp.java

public void createBufferedImages() {
    biSrc = new BufferedImage(displayImage.getWidth(this), displayImage.getHeight(this),
            BufferedImage.TYPE_INT_RGB);

    big = biSrc.createGraphics();/*from   w w  w . ja  va 2  s  . c  om*/
    big.drawImage(displayImage, 0, 0, this);

    srcRaster = biSrc.getRaster();

    biDest = new BufferedImage(displayImage.getWidth(this), displayImage.getHeight(this),
            BufferedImage.TYPE_INT_RGB);

    dstRaster = (WritableRaster) biDest.getRaster();
}

From source file:br.prof.salesfilho.oci.image.ImageProcessor.java

public BufferedImage resize(int newWidth, int newHeigth) {
    Image tmp = image.getScaledInstance(newWidth, newHeigth, Image.SCALE_SMOOTH);
    BufferedImage dimg = new BufferedImage(newWidth, newHeigth, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2d = dimg.createGraphics();
    g2d.drawImage(tmp, 0, 0, null);//from   w w  w  .jav a  2  s  .  c  om
    g2d.dispose();
    this.image = dimg;
    return this.image;
}