Package javax.imageio

Examples of javax.imageio.ImageWriter


                // peeves in JAXB RI as well, so if you fix this, submit the
                // code to the JAXB RI as well (see RuntimeBuiltinLeafInfoImpl)! - DD
                ByteArrayOutputStream bos = new ByteArrayOutputStream(2048);
                Iterator<ImageWriter> writers = ImageIO.getImageWritersByMIMEType(ct);
                if (writers.hasNext()) {
                    ImageWriter writer = writers.next();
                   
                    try {
                        BufferedImage bimg = convertToBufferedImage((Image) o);
                        ImageOutputStream out = ImageIO.createImageOutputStream(bos);
                        writer.setOutput(out);
                        writer.write(bimg);
                        writer.dispose();
                        out.flush();
                        out.close();
                        bos.close();
                    } catch (IOException e) {
                        throw new Fault(e);
View Full Code Here


    }
    public static byte[] getImageBytes(Image image, String type) throws IOException {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();

        BufferedImage bufImage = convertToBufferedImage(image);
        ImageWriter writer = null;
        Iterator i = ImageIO.getImageWritersByMIMEType(type);
        if (i.hasNext()) {
            writer = (ImageWriter)i.next();
        }
        if (writer != null) {
            ImageOutputStream stream = null;
            stream = ImageIO.createImageOutputStream(baos);
            writer.setOutput(stream);
            writer.write(bufImage);
            stream.close();
            return baos.toByteArray();
        }
        return null;
    }
View Full Code Here

     * @throws Exception if an error prevents image encoding
     */
    public void saveImage(String mimeType, Image image, OutputStream os)
            throws Exception {

        ImageWriter writer = null;
        Iterator iter = javax.imageio.ImageIO.getImageWritersByMIMEType(mimeType);
        if (iter.hasNext()) {
            writer = (ImageWriter) iter.next();
        }
        writer.setOutput(javax.imageio.ImageIO.createImageOutputStream(os));
        BufferedImage rendImage = null;
        if (image instanceof BufferedImage) {
            rendImage = (BufferedImage) image;
        } else {
            MediaTracker tracker = new MediaTracker(this);
            tracker.addImage(image, 0);
            tracker.waitForAll();
            rendImage = new BufferedImage(image.getWidth(null), image.getHeight(null), 1);
            Graphics g = rendImage.createGraphics();
            g.drawImage(image, 0, 0, null);
        }
        writer.write(new IIOImage(rendImage, null, null));
        writer.dispose();
    } // saveImage
View Full Code Here

     * @throws Exception if an error prevents image encoding
     */
    public void saveImage(String mimeType, Image image, OutputStream os)
            throws Exception {

        ImageWriter writer = null;
        Iterator iter = javax.imageio.ImageIO.getImageWritersByMIMEType(mimeType);
        if (iter.hasNext()) {
            writer = (ImageWriter) iter.next();
        }
        ImageOutputStream ios = javax.imageio.ImageIO.createImageOutputStream(os);
        writer.setOutput(ios);
        BufferedImage rendImage = null;
        if (image instanceof BufferedImage) {
            rendImage = (BufferedImage) image;
        } else {
            MediaTracker tracker = new MediaTracker(this);
            tracker.addImage(image, 0);
            tracker.waitForAll();
            rendImage = new BufferedImage(image.getWidth(null), image.getHeight(null), 1);
            Graphics g = rendImage.createGraphics();
            g.drawImage(image, 0, 0, null);
        }
        writer.write(new IIOImage(rendImage, null, null));
        ios.flush();
        writer.dispose();
    } // saveImage
View Full Code Here

                    OutputStream outputStream ) throws ChartDataException, PropertyException, IOException
  {
    BufferedImage bufferedImage = BinaryEncoderUtil.render( chart );

    Iterator writers = ImageIO.getImageWritersByFormatName( JPEG );
    ImageWriter imageWriter = (ImageWriter) writers.next();

    JPEGImageWriteParam params = new JPEGImageWriteParam( null );
    params.setCompressionMode( ImageWriteParam.MODE_EXPLICIT );
    params.setCompressionQuality( quality );
    params.setProgressiveMode( javax.imageio.ImageWriteParam.MODE_DISABLED );
    params.setDestinationType( new ImageTypeSpecifier( IndexColorModel.getRGBdefault(),
                                      IndexColorModel.getRGBdefault().createCompatibleSampleModel( 16, 16 ) ) );

    ImageOutputStream imageOutputStream = ImageIO.createImageOutputStream( outputStream );
    imageWriter.setOutput( imageOutputStream );
    imageWriter.write( null, new IIOImage( bufferedImage, null, null ), params );

    imageOutputStream.close();

    imageWriter.dispose();
  }
View Full Code Here

    private void writeEmbedded(IIOImage image,
                               ImageWriteParam bmpParam) throws IOException {
        String format =
            compressionType == BMPConstants.BI_JPEG ? "jpeg" : "png";
        Iterator iterator = ImageIO.getImageWritersByFormatName(format);
        ImageWriter writer = null;
        if (iterator.hasNext())
            writer = (ImageWriter)iterator.next();
        if (writer != null) {
            if (embedded_stream == null) {
                throw new RuntimeException("No stream for writing embedded image!");
            }

            writer.addIIOWriteProgressListener(new IIOWriteProgressAdapter() {
                    public void imageProgress(ImageWriter source, float percentageDone) {
                        processImageProgress(percentageDone);
                    }
                });

            writer.addIIOWriteWarningListener(new IIOWriteWarningListener() {
                    public void warningOccurred(ImageWriter source, int imageIndex, String warning) {
                        processWarningOccurred(imageIndex, warning);
                    }
                });
            writer.setOutput(ImageIO.createImageOutputStream(embedded_stream));
            ImageWriteParam param = writer.getDefaultWriteParam();
            //param.setDestinationBands(bmpParam.getDestinationBands());
            param.setDestinationOffset(bmpParam.getDestinationOffset());
            param.setSourceBands(bmpParam.getSourceBands());
            param.setSourceRegion(bmpParam.getSourceRegion());
            param.setSourceSubsampling(bmpParam.getSourceXSubsampling(),
                                       bmpParam.getSourceYSubsampling(),
                                       bmpParam.getSubsamplingXOffset(),
                                       bmpParam.getSubsamplingYOffset());
            writer.write(null, image, param);
        } else
            throw new RuntimeException(I18N.getString("BMPImageWrite5") + " " + format);

    }
View Full Code Here

            log.debug("Thread: " + Thread.currentThread().getName() + " writing: " + tileIdx);
        }

        // TODO should we recycle the writers ?
        // GR: it'd be only a 2% perf gain according to profiler
        ImageWriter writer = javax.imageio.ImageIO.getImageWritersByFormatName(format).next();
        ImageWriteParam param = writer.getDefaultWriteParam();

        if (this.formatModifier != null) {
            param = formatModifier.adjustImageWriteParam(param);
        }

        Rectangle tileRegion = tiles[tileIdx];
        RenderedImage tile = createTile(tileRegion.x, tileRegion.y, tileRegion.width,
                tileRegion.height);

        OutputStream outputStream = target.getOutputStream();
        ImageOutputStream imgOut = new MemoryCacheImageOutputStream(outputStream);
        writer.setOutput(imgOut);
        IIOImage image = new IIOImage(tile, null, null);
        try {
            writer.write(null, image, param);
        } finally {
            imgOut.close();
            writer.dispose();
        }

        return true;
    }
View Full Code Here

            BufferedImage newImage = UiUtilities.scaleIconToBufferedImage(tempPic, newx, newy);

            ByteArrayOutputStream out = new ByteArrayOutputStream();

            // Find a jpeg writer
            ImageWriter writer = null;
            Iterator<ImageWriter> iter = ImageIO.getImageWritersByFormatName("jpg");
            if (iter.hasNext()) {
                writer = iter.next();
            }

            if (writer != null) {
                // Prepare output file
                ImageOutputStream ios = ImageIO.createImageOutputStream(out);
                writer.setOutput(ios);

                JPEGImageWriteParam param = new JPEGImageWriteParam(null);

                param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
                param.setCompressionQuality(0.85f);

                // Write the image
                writer.write(null, new IIOImage(newImage, null, null), param);

                // Cleanup
                ios.flush();
                writer.dispose();
                ios.close();

                newdata = out.toByteArray();
            } else {
                mLog.severe("No JPEG-Exporter found. Image is not stored in Data");
View Full Code Here

    public void writeTo(Object obj, String mimeType, OutputStream os) throws IOException {
        Iterator i = ImageIO.getImageWritersByMIMEType(mimeType);
        if (!i.hasNext()) {
            throw new UnsupportedDataTypeException("Unknown image type " + mimeType);
        }
        ImageWriter writer = (ImageWriter) i.next();
        writer.setOutput(os);

        if (obj instanceof RenderedImage) {
            writer.write((RenderedImage) obj);
        } else if (obj instanceof BufferedImage) {
            BufferedImage buffered = (BufferedImage) obj;
            writer.write(new IIOImage(buffered.getRaster(), null, null));
        } else if (obj instanceof Image) {
            Image image = (Image) obj;
            BufferedImage buffered = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB);
            Graphics2D graphics = buffered.createGraphics();
            graphics.drawImage(image, 0, 0, null, null);
            writer.write(new IIOImage(buffered.getRaster(), null, null));
        } else {
            throw new UnsupportedDataTypeException("Unknown image type " + obj.getClass().getName());
        }
        os.flush();
    }
View Full Code Here

                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                ImageWriteParam iwparam = new JPEGImageWriteParam(Locale.getDefault());
                iwparam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
                iwparam.setCompressionQuality(jpegQuality);//Set here your compression rate
                ImageWriter iw = ImageIO.getImageWritersByFormatName("jpg").next();
                ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
                iw.setOutput(ios);
                iw.write(null, new IIOImage(scaled, null, null), iwparam);
                iw.dispose();
                ios.close();

                scaled.flush();
                scaled = null;
                image = com.itextpdf.text.Image.getInstance(baos.toByteArray());
View Full Code Here

TOP

Related Classes of javax.imageio.ImageWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.