|
java.lang.Object
com.aspose.words.ImageData
public class ImageData - extends java.lang.Object
Defines an image for a shape.
Use the Shape.ImageData property to access and modify the image inside a shape.
You do not create instances of the ImageData class directly. An image can be stored inside a shape, linked to external file or both (linked and stored in the document). Regardless of whether the image is stored inside the shape or linked, you can always access the actual
image using the toImage(), toInputStream() and save(java.lang.String) methods.
If the image is stored inside the shape, you can also directly access it using the
ImageBytes property. To store an image inside a shape use the setImage(java.lang.String) method. To link an image
to a shape, set the SourceFullName property. Example: Shows how to extract images from a document.
Document doc = new Document(getMyDir() + "Image.SampleImages.doc");
NodeCollection shapes = doc.getChildNodes(NodeType.SHAPE, true, false);
int imageIndex = 0;
for(int i = 0; i < shapes.getCount(); i++)
{
Shape shape = (Shape)shapes.get(i);
if (shape.hasImage())
{
String imageFileName = MessageFormat.format("Image.ExportImages.{0} Out.{1}", imageIndex, shape.getImageData().getImageType());
shape.getImageData().save(getMyDir() + imageFileName);
imageIndex++;
}
}Example: Shows how to insert a linked image into a document.
DocumentBuilder builder = new DocumentBuilder();
String imageFileName = getMyDir() + "Hammer.wmf";
builder.write("Image linked, not stored in the document: ");
Shape linkedOnly = new Shape(builder.getDocument(), ShapeType.IMAGE);
linkedOnly.setWrapType(WrapType.INLINE);
linkedOnly.getImageData().setSourceFullName(imageFileName);
builder.insertNode(linkedOnly);
builder.writeln();
builder.write("Image linked and stored in the document: ");
Shape linkedAndStored = new Shape(builder.getDocument(), ShapeType.IMAGE);
linkedAndStored.setWrapType(WrapType.INLINE);
linkedAndStored.getImageData().setSourceFullName(imageFileName);
linkedAndStored.getImageData().setImage(imageFileName);
builder.insertNode(linkedAndStored);
builder.writeln();
builder.write("Image stored in the document, but not linked: ");
Shape stored = new Shape(builder.getDocument(), ShapeType.IMAGE);
stored.setWrapType(WrapType.INLINE);
stored.getImageData().setImage(imageFileName);
builder.insertNode(stored);
builder.writeln();
builder.getDocument().save(getMyDir() + "Image.CreateLinkedImage Out.doc");
|
Property Getters/Setters Summary |
boolean | getBiLevel() | | void | setBiLevel(boolean value) | |
|
Determines whether an image will be displayed in black and white.
|
Borders | getBorders() | | |
Gets the collection of borders of the image. Borders only have effect for inline images.
|
double | getBrightness() | | void | setBrightness(double value) | |
|
Gets or sets the brightness of the picture.
The value for this property must be a number from 0.0 (dimmest) to 1.0 (brightest).
|
java.awt.Color | getChromaKey() | | void | setChromaKey(java.awt.Color value) | |
|
Defines the color value of the image that will be treated as transparent.
|
double | getContrast() | | void | setContrast(double value) | |
|
Gets or sets the contrast for the specified picture. The value
for this property must be a number from 0.0 (the least contrast) to 1.0 (the greatest contrast).
|
double | getCropBottom() | | void | setCropBottom(double value) | |
|
Defines the fraction of picture removal from the bottom side.
|
double | getCropLeft() | | void | setCropLeft(double value) | |
|
Defines the fraction of picture removal from the left side.
|
double | getCropRight() | | void | setCropRight(double value) | |
|
Defines the fraction of picture removal from the right side.
|
double | getCropTop() | | void | setCropTop(double value) | |
|
Defines the fraction of picture removal from the top side.
|
boolean | getGrayScale() | | void | setGrayScale(boolean value) | |
|
Determines whether a picture will display in grayscale mode.
|
boolean | hasImage() | | |
Returns true if the shape has image bytes or links an image.
|
byte[] | getImageBytes() | | |
Gets the raw bytes of the image stored in the shape.
|
ImageSize | getImageSize() | | |
Gets the information about image size and resolution.
|
int | getImageType() | | |
Gets the type of the image.
The value of the property is ImageType integer constant. |
boolean | isLink() | | |
Returns true if the image is linked to the shape (when SourceFullName is specified).
|
boolean | isLinkOnly() | | |
Returns true if the image is linked and not stored in the document.
|
java.lang.String | getSourceFullName() | | void | setSourceFullName(java.lang.String value) | |
|
Gets or sets the path and name of the source file for the linked image.
|
java.lang.String | getTitle() | | void | setTitle(java.lang.String value) | |
|
Defines the title of an image.
|
|
Method Summary |
java.lang.Object | fetchInheritedBorderAttr(int key) | |
|
IBorderAttrSource
|
java.lang.Object | getDirectBorderAttr(int key) | |
|
IBorderAttrSource
|
void | save(java.io.OutputStream stream) | |
|
Saves the image into the specified stream.
|
void | save(java.lang.String fileName) | |
|
Saves the image into a file.
|
void | setBorderAttr(int key, java.lang.Object value) | |
|
IBorderAttrSource
|
void | setImage(byte[] imageBytes) | |
|
Sets the image that the shape displays.
|
void | setImage(java.awt.image.BufferedImage image) | |
|
Sets the image that the shape displays.
|
void | setImage(java.io.InputStream stream) | |
|
Sets the image that the shape displays.
|
void | setImage(java.lang.String fileName) | |
|
Sets the image that the shape displays.
|
java.awt.image.BufferedImage | toImage() | |
|
Gets the image stored in the shape as a java BufferedImage object.
|
java.io.InputStream | toInputStream() | |
|
Creates and returns a stream that contains the image bytes.
|
|
Property Getters/Setters Detail |
getImageBytes | |
public byte[] getImageBytes()
|
-
Gets the raw bytes of the image stored in the shape.
Returns null if the image is not stored in the document. - See Also:
- setImage(java.lang.String), toImage(), toInputStream(), save(java.lang.String)
hasImage | |
public boolean hasImage()
|
-
Returns true if the shape has image bytes or links an image.
-
Gets the information about image size and resolution.
If the image is linked only and not stored in the document, returns zero size. Example: Shows how to resize an image shape.
DocumentBuilder builder = new DocumentBuilder();
// By default, the image is inserted at 100% scale.
Shape shape = builder.insertImage(getMyDir() + "Aspose.Words.gif");
// It is easy to change the shape size. In this case, make it 50% relative to the current shape size.
shape.setWidth(shape.getWidth() * 0.5);
shape.setHeight(shape.getHeight() * 0.5);
// However, we can also go back to the original image size and scale from there, say 110%.
ImageSize imageSize = shape.getImageData().getImageSize();
shape.setWidth(imageSize.getWidthPoints() * 1.1);
shape.setHeight(imageSize.getHeightPoints() * 1.1);
builder.getDocument().save(getMyDir() + "Image.ScaleImage Out.doc");
getImageType | |
public int getImageType()
|
-
Gets the type of the image.
The value of the property is ImageType integer constant.
Example: Shows how to extract images from a document.
Document doc = new Document(getMyDir() + "Image.SampleImages.doc");
NodeCollection shapes = doc.getChildNodes(NodeType.SHAPE, true, false);
int imageIndex = 0;
for(int i = 0; i < shapes.getCount(); i++)
{
Shape shape = (Shape)shapes.get(i);
if (shape.hasImage())
{
String imageFileName = MessageFormat.format("Image.ExportImages.{0} Out.{1}", imageIndex, shape.getImageData().getImageType());
shape.getImageData().save(getMyDir() + imageFileName);
imageIndex++;
}
}
getSourceFullName/setSourceFullName | |
|