/** @see nextapp.echo2.app.StreamImageReference#render(java.io.OutputStream) */
 public void render(OutputStream out) throws IOException {
   if (isKeptInMemory()) {
     byte[] bytes = (byte[]) refEncodedBytes.get();
     //
     // the GC may have reaped out bytes or the image may
     // no longer be valid.  Either way we need to encode.
     //
     if (bytes == null || !isValid()) {
       Image image = getImage();
       if (image == null) return;
       ByteArrayOutputStream ba = new ByteArrayOutputStream();
       encoder.encode(image, ba);
       bytes = ba.toByteArray();
       refEncodedBytes = new SoftReference(bytes);
       setValid(true);
       //
       // tell any imagelisteners that the image has changed
       update();
     }
     out.write(bytes);
   } else {
     Image image = getImage();
     if (image == null) return;
     encoder.encode(image, out);
   }
 }
Example #2
0
 /**
  * Encode the image in a specific format and write it to an OutputStream.
  *
  * @param image The image to be encoded.
  * @param format The {@link ImageFormat} to use.
  * @param outputStream The OutputStream to write the encoded image to.
  * @param quality The quality to use for the image encoding (not supported by all ImageEncoders).
  * @param encodeAlpha Whether to encode alpha transparency (not supported by all ImageEncoders).
  * @throws IOException if there is an IO problem.
  */
 public static void writeBufferedImage(
     BufferedImage image,
     String format,
     OutputStream outputStream,
     float quality,
     boolean encodeAlpha)
     throws IOException {
   ImageEncoder imageEncoder = ImageEncoderFactory.newInstance(format, quality, encodeAlpha);
   imageEncoder.encode(image, outputStream);
 }
Example #3
0
 /**
  * Encode the image in a specific format.
  *
  * @param image The image to be encoded.
  * @param format The {@link ImageFormat} to use.
  * @param quality The quality to use for the image encoding (not supported by all ImageEncoders).
  * @return The byte[] that is the encoded image.
  * @throws IOException if there is an IO problem.
  */
 public static byte[] encode(BufferedImage image, String format, float quality)
     throws IOException {
   ImageEncoder imageEncoder = ImageEncoderFactory.newInstance(format, quality);
   return imageEncoder.encode(image);
 }
Example #4
0
 /**
  * Encode the image in a specific format.
  *
  * @param image The image to be encoded.
  * @param format The {@link ImageFormat} to use.
  * @param encodeAlpha Whether to encode alpha transparency (not supported by all ImageEncoders).
  * @return The byte[] that is the encoded image.
  * @throws IOException if there is an IO problem.
  */
 public static byte[] encode(BufferedImage image, String format, boolean encodeAlpha)
     throws IOException {
   ImageEncoder imageEncoder = ImageEncoderFactory.newInstance(format, encodeAlpha);
   return imageEncoder.encode(image);
 }
Example #5
0
 /**
  * Encode the image in a specific format and write it to an OutputStream.
  *
  * @param image The image to be encoded.
  * @param format The {@link ImageFormat} to use.
  * @param outputStream The OutputStream to write the encoded image to.
  * @throws IOException if there is an IO problem.
  */
 public static void writeBufferedImage(
     BufferedImage image, String format, OutputStream outputStream) throws IOException {
   ImageEncoder imageEncoder = ImageEncoderFactory.newInstance(format);
   imageEncoder.encode(image, outputStream);
 }