public class ImageData
extends java.lang.Object
Use the Shape.getImageData() 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 toByteArray(), toImage() or save(java.lang.String) methods. If the image is stored inside the shape, you can also directly access it using the getImageBytes() / setImageBytes(byte[]) property.
To store an image inside a shape use the setImage(java.lang.String) method. To link an image to a shape, set the getSourceFullName() / setSourceFullName(java.lang.String) property.
| Modifier and Type | Method and Description |
|---|---|
java.lang.Object |
fetchInheritedBorderAttr(int key) |
boolean |
getBiLevel()
Determines whether an image will be displayed in black and white.
|
BorderCollection |
getBorders()
Gets the collection of borders of the image.
|
double |
getBrightness()
Gets the brightness of the picture.
|
java.awt.Color |
getChromaKey()
Defines the color value of the image that will be treated as transparent.
|
double |
getContrast()
Gets the contrast for the specified picture.
|
double |
getCropBottom()
Defines the fraction of picture removal from the bottom side.
|
double |
getCropLeft()
Defines the fraction of picture removal from the left side.
|
double |
getCropRight()
Defines the fraction of picture removal from the right side.
|
double |
getCropTop()
Defines the fraction of picture removal from the top side.
|
java.lang.Object |
getDirectBorderAttr(int key) |
boolean |
getGrayScale()
Determines whether a picture will display in grayscale mode.
|
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.
|
java.lang.String |
getSourceFullName()
Gets the path and name of the source file for the linked image.
|
java.lang.String |
getTitle()
Defines the title of an image.
|
boolean |
hasImage()
Returns true if the shape has image bytes or links an image.
|
boolean |
isLink()
Returns true if the image is linked to the shape (when
getSourceFullName() / setSourceFullName(java.lang.String) is specified). |
boolean |
isLinkOnly()
Returns true if the image is linked and not stored in the document.
|
void |
save(java.io.OutputStream stream) |
void |
save(java.lang.String fileName)
Saves the image into a file.
|
void |
setBiLevel(boolean value)
Determines whether an image will be displayed in black and white.
|
void |
setBorderAttr(int key,
java.lang.Object value) |
void |
setBrightness(double value)
Sets the brightness of the picture.
|
void |
setChromaKey(java.awt.Color value)
Defines the color value of the image that will be treated as transparent.
|
void |
setContrast(double value)
Sets the contrast for the specified picture.
|
void |
setCropBottom(double value)
Defines the fraction of picture removal from the bottom side.
|
void |
setCropLeft(double value)
Defines the fraction of picture removal from the left side.
|
void |
setCropRight(double value)
Defines the fraction of picture removal from the right side.
|
void |
setCropTop(double value)
Defines the fraction of picture removal from the top side.
|
void |
setGrayScale(boolean value)
Determines whether a picture will display in grayscale mode.
|
void |
setImage(java.awt.image.BufferedImage image)
Sets the image that the shape displays.
|
void |
setImage(java.io.InputStream stream) |
void |
setImage(java.lang.String fileName)
Sets the image that the shape displays.
|
void |
setImageBytes(byte[] value)
Sets the raw bytes of the image stored in the shape.
|
void |
setSourceFullName(java.lang.String value)
Sets the path and name of the source file for the linked image.
|
void |
setTitle(java.lang.String value)
Defines the title of an image.
|
byte[] |
toByteArray()
Returns image bytes for any image regardless whether the image is stored or linked.
|
java.awt.image.BufferedImage |
toImage()
Gets the image stored in the shape as a java
BufferedImage
object.
|
java.io.InputStream |
toStream()
Creates and returns a stream that contains the image bytes.
|
public void setImage(java.awt.image.BufferedImage image)
throws java.lang.Exception
image - The image object.java.lang.Exceptionpublic void setImage(java.io.InputStream stream)
throws java.lang.Exception
java.lang.Exceptionpublic void setImage(java.lang.String fileName)
throws java.lang.Exception
fileName - The image file. Can be a file name or a URL.java.lang.Exceptionpublic java.awt.image.BufferedImage toImage()
throws java.lang.Exception
java.lang.Exceptionpublic java.io.InputStream toStream()
throws java.lang.Exception
If the image bytes are stored in the shape, creates and returns a object.
If the image is linked and stored in a file, opens the file and returns a object.
If the image is linked and stored in an external URL, opens the URL and returns a object.
Is it the responsibility of the caller to dispose the stream object.
java.lang.Exceptionpublic byte[] toByteArray()
throws java.lang.Exception
java.lang.ExceptiongetImageBytes(),
setImageBytes(byte[])public void save(java.io.OutputStream stream)
throws java.lang.Exception
java.lang.Exceptionpublic void save(java.lang.String fileName)
throws java.lang.Exception
fileName - The file name where to save the image.java.lang.Exceptionpublic byte[] getImageBytes()
throws java.lang.Exception
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).
java.lang.ExceptionsetImage(java.lang.String),
toByteArray(),
toImage(),
save(java.lang.String)public void setImageBytes(byte[] value)
throws java.lang.Exception
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).
value - The raw bytes of the image stored in the shape.java.lang.ExceptionsetImage(java.lang.String),
toByteArray(),
toImage(),
save(java.lang.String)public boolean hasImage()
throws java.lang.Exception
java.lang.Exceptionpublic ImageSize getImageSize() throws java.lang.Exception
If the image is linked only and not stored in the document, returns zero size.
java.lang.Exceptionpublic int getImageType()
throws java.lang.Exception
ImageType constants.java.lang.Exceptionpublic boolean isLink()
throws java.lang.Exception
getSourceFullName() / setSourceFullName(java.lang.String) is specified). getSourceFullName() / setSourceFullName(java.lang.String) is specified).java.lang.Exceptionpublic boolean isLinkOnly()
throws java.lang.Exception
java.lang.Exceptionpublic java.lang.String getSourceFullName()
throws java.lang.Exception
The default value is an empty string.
If getSourceFullName() / setSourceFullName(java.lang.String) is not an empty string, the image is linked.
java.lang.Exceptionpublic void setSourceFullName(java.lang.String value)
throws java.lang.Exception
The default value is an empty string.
If getSourceFullName() / setSourceFullName(java.lang.String) is not an empty string, the image is linked.
value - The path and name of the source file for the linked image.java.lang.Exceptionpublic java.lang.String getTitle()
The default value is an empty string.
String value.public void setTitle(java.lang.String value)
The default value is an empty string.
value - The corresponding String value.public double getCropTop()
The amount of cropping can range from -1.0 to 1.0. The default value is 0. Note that a value of 1 will display no picture at all. Negative values will result in the picture being squeezed inward from the edge being cropped (the empty space between the picture and the cropped edge will be filled by the fill color of the shape). Positive values less than 1 will result in the remaining picture being stretched to fit the shape.
The default value is 0.
double value.public void setCropTop(double value)
The amount of cropping can range from -1.0 to 1.0. The default value is 0. Note that a value of 1 will display no picture at all. Negative values will result in the picture being squeezed inward from the edge being cropped (the empty space between the picture and the cropped edge will be filled by the fill color of the shape). Positive values less than 1 will result in the remaining picture being stretched to fit the shape.
The default value is 0.
value - The corresponding double value.public double getCropBottom()
The amount of cropping can range from -1.0 to 1.0. The default value is 0. Note that a value of 1 will display no picture at all. Negative values will result in the picture being squeezed inward from the edge being cropped (the empty space between the picture and the cropped edge will be filled by the fill color of the shape). Positive values less than 1 will result in the remaining picture being stretched to fit the shape.
The default value is 0.
double value.public void setCropBottom(double value)
The amount of cropping can range from -1.0 to 1.0. The default value is 0. Note that a value of 1 will display no picture at all. Negative values will result in the picture being squeezed inward from the edge being cropped (the empty space between the picture and the cropped edge will be filled by the fill color of the shape). Positive values less than 1 will result in the remaining picture being stretched to fit the shape.
The default value is 0.
value - The corresponding double value.public double getCropLeft()
The amount of cropping can range from -1.0 to 1.0. The default value is 0. Note that a value of 1 will display no picture at all. Negative values will result in the picture being squeezed inward from the edge being cropped (the empty space between the picture and the cropped edge will be filled by the fill color of the shape). Positive values less than 1 will result in the remaining picture being stretched to fit the shape.
The default value is 0.
double value.public void setCropLeft(double value)
The amount of cropping can range from -1.0 to 1.0. The default value is 0. Note that a value of 1 will display no picture at all. Negative values will result in the picture being squeezed inward from the edge being cropped (the empty space between the picture and the cropped edge will be filled by the fill color of the shape). Positive values less than 1 will result in the remaining picture being stretched to fit the shape.
The default value is 0.
value - The corresponding double value.public double getCropRight()
The amount of cropping can range from -1.0 to 1.0. The default value is 0. Note that a value of 1 will display no picture at all. Negative values will result in the picture being squeezed inward from the edge being cropped (the empty space between the picture and the cropped edge will be filled by the fill color of the shape). Positive values less than 1 will result in the remaining picture being stretched to fit the shape.
The default value is 0.
double value.public void setCropRight(double value)
The amount of cropping can range from -1.0 to 1.0. The default value is 0. Note that a value of 1 will display no picture at all. Negative values will result in the picture being squeezed inward from the edge being cropped (the empty space between the picture and the cropped edge will be filled by the fill color of the shape). Positive values less than 1 will result in the remaining picture being stretched to fit the shape.
The default value is 0.
value - The corresponding double value.public BorderCollection getBorders()
public java.awt.Color getChromaKey()
The default value is 0.
Color value.public void setChromaKey(java.awt.Color value)
The default value is 0.
value - The corresponding Color value.public double getBrightness()
The default value is 0.5.
public void setBrightness(double value)
The default value is 0.5.
value - The brightness of the picture.public double getContrast()
The default value is 0.5.
public void setContrast(double value)
The default value is 0.5.
value - The contrast for the specified picture.public boolean getBiLevel()
The default value is false.
boolean value.public void setBiLevel(boolean value)
The default value is false.
value - The corresponding boolean value.public boolean getGrayScale()
The default value is false.
boolean value.public void setGrayScale(boolean value)
The default value is false.
value - The corresponding boolean value.public java.lang.Object getDirectBorderAttr(int key)
public java.lang.Object fetchInheritedBorderAttr(int key)
public void setBorderAttr(int key,
java.lang.Object value)