Java Code Examples for javax.imageio.IIOImage#getRenderedImage()

The following examples show how to use javax.imageio.IIOImage#getRenderedImage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebPWriter.java    From j-webp with Apache License 2.0 5 votes vote down vote up
@Override
public void write(IIOMetadata streamMetadata, IIOImage image, ImageWriteParam param) throws IOException {
  if (param == null) {
    param = getDefaultWriteParam();
  }

  WebPWriteParam writeParam = (WebPWriteParam) param;

  ImageOutputStream output = (ImageOutputStream) getOutput();
  RenderedImage ri = image.getRenderedImage();

  byte[] encodedData = encode(writeParam.getEncoderOptions(), ri);
  output.write(encodedData);
}
 
Example 2
Source File: ImageHelper.java    From tess4j with Apache License 2.0 5 votes vote down vote up
/**
 * Convenience method that returns a scaled instance of the provided
 * {@code IIOImage}.
 *
 * @param iioSource the original image to be scaled
 * @param scale the desired scale
 * @return a scaled version of the original {@code IIOImage}
 */
public static IIOImage getScaledInstance(IIOImage iioSource, float scale) {
    if (!(iioSource.getRenderedImage() instanceof BufferedImage)) {
        throw new IllegalArgumentException("RenderedImage in IIOImage must be BufferedImage");
    }

    if (Math.abs(scale - 1.0) < 0.001) {
        return iioSource;
    }

    BufferedImage source = (BufferedImage) iioSource.getRenderedImage();
    BufferedImage target = getScaledInstance(source, (int) (scale * source.getWidth()), (int) (scale * source.getHeight()));
    return new IIOImage(target, null, null);
}
 
Example 3
Source File: WebPWriter.java    From webp-imageio with Apache License 2.0 5 votes vote down vote up
@Override
public void write( IIOMetadata streamMetadata, IIOImage image, ImageWriteParam param ) throws IOException {
  if ( param == null ) {
    param = getDefaultWriteParam();
  }

  WebPWriteParam writeParam = (WebPWriteParam) param;

  ImageOutputStream output = ( ImageOutputStream ) getOutput();
  RenderedImage ri = image.getRenderedImage();

  byte[] encodedData = WebP.encode(writeParam, ri);
  output.write( encodedData );
}