org.knime.core.data.image.png
Class PNGImageContent

java.lang.Object
  extended by org.knime.core.data.image.png.PNGImageContent
All Implemented Interfaces:
ImageContent

public class PNGImageContent
extends Object
implements ImageContent

Content of a PNG image. It only wraps a byte[] which is supposed to be PNG content. The rendering methods will delegate all work to BufferedImage.

Author:
Thomas Gabriel, KNIME.com, Zurich, Switzerland

Field Summary
static DataType TYPE
          Type for PNG cells.
 
Constructor Summary
PNGImageContent()
          Framework constructor for restoring content.
PNGImageContent(byte[] imageBytes)
          Creates PNG image content from byte array.
PNGImageContent(InputStream is)
          Reads image content from a stream.
 
Method Summary
(package private) static PNGImageContent deserialize(DataCellDataInput input)
          Deserialize method for DataCell implementation.
 byte[] getByteArray()
          Get a copy of the underlying byte array.
 byte[] getByteArrayReference()
          Get a reference to the underlying byte array.
 Image getImage()
          Get the image represented by this object.
 Dimension getPreferredSize()
          Preferred dimension, width and height, for the given image to be rendered.
 String getSummary()
          
 void paint(Graphics2D g, int width, int height)
          Render image into argument graphics object.
 void save(OutputStream output)
          Save the image content to an output stream.
 void serialize(DataCellDataOutput output)
          Serialize method for image content.
 DataCell toImageCell()
          Factory method to generate cell implementation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TYPE

public static final DataType TYPE
Type for PNG cells.

Constructor Detail

PNGImageContent

public PNGImageContent()
Framework constructor for restoring content. Do not use!


PNGImageContent

public PNGImageContent(byte[] imageBytes)
Creates PNG image content from byte array.

Parameters:
imageBytes - The image bytes.
Throws:
NullPointerException - If the argument is null.
IllegalArgumentException - If the argument does not represent a valid png byte stream (according to ImageIO.read(InputStream).

PNGImageContent

public PNGImageContent(InputStream is)
                throws IOException
Reads image content from a stream. The reader will read content until the end of the stream, it will not close the stream.

Parameters:
is - The input stream.
Throws:
IOException - If reading from the stream fails.
NullPointerException - If the argument is null;
IllegalArgumentException - If the argument does not represent a valid png byte stream (according to ImageIO.read(InputStream).
Method Detail

getByteArrayReference

public byte[] getByteArrayReference()
Get a reference to the underlying byte array. The caller must not modify the returned array but should use the getByteArray() if necessary.

Returns:
Reference to the underlying byte array.

getByteArray

public byte[] getByteArray()
Get a copy of the underlying byte array.

Returns:
A new copy.
See Also:
getByteArrayReference()

getImage

public Image getImage()
Get the image represented by this object.

Returns:
The image.
Throws:
IllegalStateException - If the image can't be read from the internal memory representation (the Image is not actually stored as part of this cell but kept in a SoftReference)

paint

public void paint(Graphics2D g,
                  int width,
                  int height)
Render image into argument graphics object. The aspect ration of the image must be retained, i.e. the width and height are maximum values that do not need to be fulfilled both at the same time.

Specified by:
paint in interface ImageContent
Parameters:
g - To paint to.
width - image maximum width
height - image maximum height

save

public void save(OutputStream output)
          throws IOException
Save the image content to an output stream.

Specified by:
save in interface ImageContent
Parameters:
output - To save to.
Throws:
IOException - If that fails.

deserialize

static PNGImageContent deserialize(DataCellDataInput input)
                            throws IOException
Deserialize method for DataCell implementation.

Parameters:
input - To read from.
Returns:
A new image content.
Throws:
IOException - If that fails.

serialize

public void serialize(DataCellDataOutput output)
               throws IOException
Serialize method for image content.

Parameters:
output - To save to.
Throws:
IOException - If that fails for any reason.

toImageCell

public DataCell toImageCell()
Factory method to generate cell implementation.

Specified by:
toImageCell in interface ImageContent
Returns:
A (likely new) cell representing this image.

getPreferredSize

public Dimension getPreferredSize()
Preferred dimension, width and height, for the given image to be rendered.

Specified by:
getPreferredSize in interface ImageContent
Returns:
preferred dimension

getSummary

public String getSummary()

Specified by:
getSummary in interface ImageContent
Returns:
short summary representing this image content object.


Copyright, 2003 - 2012. All rights reserved.
University of Konstanz, Germany.
Chair for Bioinformatics and Information Mining, Prof. Dr. Michael R. Berthold.
You may not modify, publish, transmit, transfer or sell, reproduce, create derivative works from, distribute, perform, display, or in any way exploit any of the content, in whole or in part, except as otherwise expressly permitted in writing by the copyright owner or as specified in the license file distributed with this product.