Package javax.imageio

Examples of javax.imageio.ImageWriter


        File content,
        UniqueIDGenerator namer,
        File uploadDirectory
    ) throws IOException {
        String originalName = null;
        ImageWriter format = null;
        BufferedImage image = null;

        originalName = "";
        format = findWriter(contentType);
        image = ImageIO.read(content);
View Full Code Here


            if (formcov!= null)
              tiled = new TiledImage(formcov,width,height);
            else
              tiled = new TiledImage(image,width,height);
            final ImageOutputStream imageOutStream = ImageIO.createImageOutputStream(out);
            final ImageWriter writer = writerSPI.createWriterInstance();
            writer.setOutput(imageOutStream);
            writer.write(tiled);
            imageOutStream.flush();
            imageOutStream.close();
          }
          else
          {
View Full Code Here

    if (LOGGER.isLoggable(Level.FINE)) {
      LOGGER.fine("Getting a writer for tiff");
    }

    // get a writer
    final ImageWriter writer = writerSPI.createWriterInstance();

    // getting a stream caching in memory
    final ImageOutputStream ioutstream = ImageIO
        .createImageOutputStream(outStream);

    // tiff
    if (LOGGER.isLoggable(Level.FINE)) {
      LOGGER.fine("Writing tiff image ...");
    }

        // get the one required by the GetMapRequest
        final String format = getOutputFormat();

        // do we want it to be 8 bits?
    if (format.equalsIgnoreCase("image/tiff8")
        || (this.mapContext.getPaletteInverter() != null)) {
      image = forceIndexed8Bitmask(image);
    }

    // write it out
    writer.setOutput(ioutstream);
    writer.write(image);
    ioutstream.close();
    writer.dispose();

    if (LOGGER.isLoggable(Level.FINE)) {
      LOGGER.fine("Writing tiff image done!");
    }
  }
View Full Code Here

        }

        // If the file does not exist or the user gives permission,
        // save image to file.

        ImageWriter writer = null;
        ImageOutputStream ios = null;

        try {
            // Obtain a writer based on the jpeg format.

            Iterator iter;
            iter = ImageIO.getImageWritersByFormatName("jpeg");

            // Validate existence of writer.

            if (!iter.hasNext()) {
                showError("Unable to save image to jpeg file type.");
                return;
            }

            // Extract writer.

            writer = (ImageWriter) iter.next();

            // Configure writer output destination.

            ios = ImageIO.createImageOutputStream(file);
            writer.setOutput(ios);

            // Set JPEG compression quality to 95%.

            ImageWriteParam iwp = writer.getDefaultWriteParam();
            iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
            iwp.setCompressionQuality(0.95f);

            // Write the image.

            writer.write(null,
                    new IIOImage((BufferedImage) imageArea.getImage(), null, null),
                    iwp);
        } catch (IOException e2) {
            showError(e2.getMessage());
        } finally {
            try {
                // Cleanup.

                if (ios != null) {
                    ios.flush();
                    ios.close();
                }

                if (writer != null) {
                    writer.dispose();
                }
            } catch (IOException e2) {
            }
        }
    }
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

        if (!it.hasNext()) {
            throw new IllegalArgumentException("Format not supported: " + format);
        }

        ImageWriter writer = (ImageWriter) it.next();
        ImageOutputStream ioutstream = null;

        IIOMetadata meta = writer.getDefaultStreamMetadata(writer.getDefaultWriteParam());
        ImageWriteParam param = writer.getDefaultWriteParam();

        // DJB: jpeg does not support ARGB (alpha) colour
        //      this converts the image from ARGB to RGB
        // TODO: make this more abstract - it should be smarter for more image
        //       writer types (Ie. ask the writer what it supports)
        //       Alternately, make a jpeg writer and png writer, as these are
        //       mostly what we get from jai!
        if (format.equalsIgnoreCase("image/jpeg")) {
            param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
            param.setCompressionQuality(0.9f); // DJB: only do this for jpegs - png freaks when you do this!

            meta = writer.getDefaultStreamMetadata(param);

            //           WritableRaster raster = image.getRaster();
            //           WritableRaster newRaster = raster.createWritableChild(0, 0, image.getWidth(), image.getHeight(), 0, 0, new int[] {0, 1, 2});
            //             create a ColorModel that represents the one of the ARGB except the alpha channel:
            //            DirectColorModel cm = (DirectColorModel)image.getColorModel();
            //           DirectColorModel newCM = new DirectColorModel(cm.getPixelSize(), cm.getRedMask(), cm.getGreenMask(), cm.getBlueMask());
            //             now create the new buffer that is used ot write the image:
            // BufferedImage rgbBuffer = new BufferedImage(newCM, newRaster, false, null);
            BufferedImage curImage = new BufferedImage(image.getWidth(), image.getHeight(),
                    BufferedImage.TYPE_3BYTE_BGR);
            Graphics2D g = (Graphics2D) curImage.createGraphics();
            g.drawImage(image, 0, 0, null);

            image = curImage;

            ioutstream = ImageIO.createImageOutputStream(outStream);
            writer.setOutput(ioutstream);
            writer.write(image);
            ioutstream.close();
            writer.dispose();

            return;
        }

        ioutstream = ImageIO.createImageOutputStream(outStream);
        writer.setOutput(ioutstream);
        writer.write(meta, new IIOImage(image, null, meta), param);
        ioutstream.close();
        writer.dispose();
    }
View Full Code Here

                    videoFrameChunk.getOutputStream().write(bytes);
                }
                break;
            }
            case JPG: {
                ImageWriter iw = ImageIO.getImageWritersByMIMEType("image/jpeg").next();
                ImageWriteParam iwParam = iw.getDefaultWriteParam();
                iwParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
                iwParam.setCompressionQuality(quality);
                MemoryCacheImageOutputStream imgOut = new MemoryCacheImageOutputStream(videoFrameChunk.getOutputStream());
                iw.setOutput(imgOut);
                IIOImage img = new IIOImage(image, null, null);
                iw.write(null, img, iwParam);
                iw.dispose();
                break;
            }
            case PNG:
            default: {
                ImageWriter iw = ImageIO.getImageWritersByMIMEType("image/png").next();
                ImageWriteParam iwParam = iw.getDefaultWriteParam();
                MemoryCacheImageOutputStream imgOut = new MemoryCacheImageOutputStream(videoFrameChunk.getOutputStream());
                iw.setOutput(imgOut);
                IIOImage img = new IIOImage(image, null, null);
                iw.write(null, img, iwParam);
                iw.dispose();
                break;
            }
        }
        long length = out.getStreamPosition() - offset;
        videoFrameChunk.finish();
View Full Code Here

   *                   be written to.
   */
  public void export(Controller controller,
                     OutputStream os) {
    Iterator it = ImageIO.getImageWritersByFormatName(format);
    ImageWriter imageWriter = null;
    Dimension size = controller.getGraphGenerator().getGraph().getShape().getBounds().getSize();
    int width = size.width + 10;
    int height = size.height + 10;
    int scaledWidth = (int) (width * scale / 100.0);
    int scaledHeight = (int) (height * scale / 100.0);
    if(width > 0 && height > 0) {
      if(it.hasNext()) {
        imageWriter = (ImageWriter) it.next();
      }
      if(imageWriter != null) {
        // Get the width and height of the graph view
        try {
          // Create an image export stream that wraps the export stream
          ImageOutputStream ios = ImageIO.createImageOutputStream(os);
          imageWriter.setOutput(ios);

          // We want to write the graphview to a buffered image
          BufferedImage bufferedImage = new BufferedImage(scaledWidth, scaledHeight, BufferedImage.TYPE_INT_RGB);
          Graphics2D g2 = (Graphics2D) bufferedImage.getGraphics();

          // Clip the image at the proper bounds
          g2.setClip(0, 0, width, height);
          if(scale != 100.0) {
            g2.scale(scale / 100.0, scale / 100.0);
          }
          controller.getGraphView().draw(g2, false, false, antialiased, true);
          imageWriter.write(bufferedImage);
          ios.close();
        }
        catch(IOException e) {
          e.printStackTrace();
        }
View Full Code Here

                // 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

     * @throws Exception if an error prevents image encoding
     */
    public void saveImage(String mimeType, BufferedImage 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);
       
        writer.write(new IIOImage(image, null, null));
        ios.flush();
        writer.dispose();
    } // saveImage
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.