Ejemplo n.º 1
0
 /**
  * Updates the metadata information based on the parameters to this writer.
  *
  * @param meta the metadata
  * @param params the parameters
  * @return the updated metadata
  */
 protected IIOMetadata updateMetadata(IIOMetadata meta, ImageWriterParams params) {
   final String stdmeta = "javax_imageio_1.0";
   if (meta.isStandardMetadataFormatSupported()) {
     IIOMetadataNode root = (IIOMetadataNode) meta.getAsTree(stdmeta);
     IIOMetadataNode dim = getChildNode(root, "Dimension");
     IIOMetadataNode child;
     if (params.getResolution() != null) {
       child = getChildNode(dim, "HorizontalPixelSize");
       if (child == null) {
         child = new IIOMetadataNode("HorizontalPixelSize");
         dim.appendChild(child);
       }
       child.setAttribute("value", Double.toString(params.getResolution().doubleValue() / 25.4));
       child = getChildNode(dim, "VerticalPixelSize");
       if (child == null) {
         child = new IIOMetadataNode("VerticalPixelSize");
         dim.appendChild(child);
       }
       child.setAttribute("value", Double.toString(params.getResolution().doubleValue() / 25.4));
     }
     try {
       meta.mergeTree(stdmeta, root);
     } catch (IIOInvalidTreeException e) {
       throw new RuntimeException("Cannot update image metadata: " + e.getMessage());
     }
   }
   return meta;
 }
Ejemplo n.º 2
0
 /**
  * Returns the default write parameters for encoding the image.
  *
  * @param iiowriter The IIO ImageWriter that will be used
  * @param image the image to be encoded
  * @param params the parameters for this writer instance
  * @return the IIO ImageWriteParam instance
  */
 protected ImageWriteParam getDefaultWriteParam(
     javax.imageio.ImageWriter iiowriter, RenderedImage image, ImageWriterParams params) {
   ImageWriteParam param = iiowriter.getDefaultWriteParam();
   System.err.println("Param: " + params);
   if ((params != null) && (params.getCompressionMethod() != null)) {
     param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
     param.setCompressionType(params.getCompressionMethod());
   }
   return param;
 }
Ejemplo n.º 3
0
 /**
  * @see ImageWriter#writeImage(java.awt.image.RenderedImage, java.io.OutputStream,
  *     org.apache.batik.ext.awt.image.spi.ImageWriterParams)
  */
 public void writeImage(RenderedImage image, OutputStream out, ImageWriterParams params)
     throws IOException {
   BufferedImage bi;
   if (image instanceof BufferedImage) {
     bi = (BufferedImage) image;
   } else {
     // TODO Is this the right way?
     bi = GraphicsUtil.makeLinearBufferedImage(image.getWidth(), image.getHeight(), false);
   }
   JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
   if (params != null) {
     JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bi);
     if (params.getJPEGQuality() != null) {
       param.setQuality(
           params.getJPEGQuality().floatValue(), params.getJPEGForceBaseline().booleanValue());
     }
     encoder.encode(bi, param);
   } else {
     encoder.encode(bi);
   }
 }