com.aspose.words
Interface IImageData

All Known Implementing Classes:
ImageData, DrawingMLImageData

public interface IImageData 

Provides a common interface for manipulating images stored in VML-based and DrawingML-based shapes in a document.

You can use this interface if you want to process images stored in a document (e.g. extract or replace) and you want to do that using the same code both for images stored in "old" VML-based and "new" DrawingML-based shapes.

Documents created by Microsoft Word 2003 or earlier had one type of graphical objects. These objects were VML (Vector Markup Language) based. In the Aspose.Words document model such objects are represented by the Shape and GroupShape classes. These shapes can be images or can contain images. You can access these images via the Shape.ImageData property that returns an object of the ImageData class.

Documents created by Microsoft Word 2007 or newer can have two types of graphical objects. The old VML-based shapes and also the new DrawingML-based shapes. DrawingML is part of the Office Open XML standard. In the Aspose.Words document model the new DrawingML-based shapes are represented by the DrawingML class. DrawingML shapes can also contain images. You can access these images via the DrawingML.ImageData property that returns an object of the DrawingMLImageData class.

The Shape and DrawingML classes are different because the underlying document elements are different. As a result, the two classes have two different mechanisms to access their respective image data using the ImageData and DrawingMLImageData classes. But there is some similarity between the two when it comes to operations with images and these operations are extracted into this IImageData interface for your convenience.


Property Getters/Setters Summary
abstract booleanhasImage()
           Returns true if the shape has image bytes or links an image.
abstract byte[]getImageBytes()
abstract voidsetImageBytes(byte[] value)
           Gets or sets the raw bytes of the image stored in the shape.
abstract ImageSizegetImageSize()
           Gets the information about image size and resolution.
abstract intgetImageType()
           Gets the type of the image. The value of the property is ImageType integer constant.
abstract booleanisLink()
           Returns true if the image is linked to the shape (when SourceFullName is specified).
abstract booleanisLinkOnly()
           Returns true if the image is linked and not stored in the document.
abstract java.lang.StringgetSourceFullName()
abstract voidsetSourceFullName(java.lang.String value)
           Gets or sets the path and name of the source file for the linked image.
 
Method Summary
abstract voidsave(java.io.OutputStream stream)
           Saves the image into the specified stream.
abstract voidsave(java.lang.String fileName)
           Saves the image into a file.
abstract voidsetImage(java.awt.image.BufferedImage image)
           Sets the image that the shape displays.
abstract voidsetImage(java.io.InputStream stream)
           Sets the image that the shape displays.
abstract voidsetImage(java.lang.String fileName)
           Sets the image that the shape displays.
abstract byte[]toByteArray()
           Returns image bytes for any image regardless whether the image is stored or linked.
abstract java.awt.image.BufferedImagetoImage()
           Gets the image stored in the shape as a java BufferedImage object.
 

Property Getters/Setters Detail

hasImage

public abstract boolean hasImage()
Returns true if the shape has image bytes or links an image.

getImageBytes/setImageBytes

public abstract byte[] getImageBytes() / public abstract void setImageBytes(byte[] value)
Gets or sets the raw bytes of the image stored in the shape.

Setting the value to null or an empty array will remove the image from the shape.

Returns null if the image is not stored in the document (e.g the image is probably linked in this case).

See Also:
setImage(java.lang.String), toByteArray(), toImage(), save(java.lang.String)

getImageSize

public abstract ImageSize getImageSize()
Gets the information about image size and resolution.

If the image is linked only and not stored in the document, returns zero size.


getImageType

public abstract int getImageType()
Gets the type of the image. The value of the property is ImageType integer constant.

isLink

public abstract boolean isLink()
Returns true if the image is linked to the shape (when SourceFullName is specified).

isLinkOnly

public abstract boolean isLinkOnly()
Returns true if the image is linked and not stored in the document.

getSourceFullName/setSourceFullName

public abstract java.lang.String getSourceFullName() / public abstract void setSourceFullName(java.lang.String value)
Gets or sets the path and name of the source file for the linked image.

The default value is an empty string.

If SourceFullName is not an empty string, the image is linked.

If SourceFullName is not an empty string, but ImageBytes is null, then the image is linked and not stored in the document.


Method Detail

save

public abstract void save(java.io.OutputStream stream)
                       throws java.lang.Exception
Saves the image into the specified stream.

Is it the responsibility of the caller to dispose the stream object.

Parameters:
stream - The stream where to save the image to.

save

public abstract void save(java.lang.String fileName)
                       throws java.lang.Exception
Saves the image into a file.
Parameters:
fileName - The file name where to save the image.

setImage

public abstract void setImage(java.awt.image.BufferedImage image)
                           throws java.lang.Exception
Sets the image that the shape displays.
Parameters:
image - The image object.

setImage

public abstract void setImage(java.io.InputStream stream)
                           throws java.lang.Exception
Sets the image that the shape displays.
Parameters:
stream - The stream that contains the image. The stream will be read from the current position.

setImage

public abstract void setImage(java.lang.String fileName)
                           throws java.lang.Exception
Sets the image that the shape displays.
Parameters:
fileName - The image file. Can be a file name or a URL.

toByteArray

public abstract byte[] toByteArray()
                                throws java.lang.Exception
Returns image bytes for any image regardless whether the image is stored or linked.

If the image is linked, downloads the image every time it is called.

See Also:
ImageBytes

toImage

public abstract java.awt.image.BufferedImage toImage()
                                   throws java.lang.Exception
Gets the image stored in the shape as a java BufferedImage object.

Tries to create a new java.awt.image.BufferedImage object from image bytes every time this method is called. If javax.imageio.ImageReader can't read image bytes (emf, wmf, tiff, etc.) the method returns null.

It is the responsibility of the caller to dispose the image object.


See Also:
          Aspose.Words Documentation - the home page for the Aspose.Words Product Documentation.
          Aspose.Words Support Forum - our preferred method of support.