Class ImageTool
java.lang.Object
java.util.Observable
com.nomagic.magicreport.engine.Tool
com.nomagic.magicreport.engine.tools.ImageTool
- All Implemented Interfaces:
ITool,IVariable,Serializable,Cloneable
A tool provides functions for manipulate image.
- Since:
- July 02, 2008
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassClass that store image and its properties e.g., format, path ect.Nested classes/interfaces inherited from interface com.nomagic.magicreport.engine.ITool
ITool.HTMLString, ITool.RetainedString, ITool.Void -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringContains a context name.static final intThe default DPI which is 96.static final intThe scaling quality high.static final intThe scaling quality highest.static final intThe scaling quality low.static final intThe scaling quality lowest.static final intThe scaling quality medium.static final intConstant value for paper size.static final intConstant value for paper size.Fields inherited from class com.nomagic.magicreport.engine.Tool
context, properties -
Constructor Summary
ConstructorsConstructorDescriptionPrevent empty initiate.ImageTool(ITemplateEngine engine) Create an image tool with engine. -
Method Summary
Modifier and TypeMethodDescriptionprotected float[]Deprecated.Copy an external image from local file or URL into report.protected IFormatterWrappercreateFormatterWrapper(Class<?> engineClass) Create the formatter wrapper from given engine class.createImageWithAbsolutePath(Image image) Export image and return absolute path of the file.
This method is suitable for TXT, HTML and XML template only.
Use the method with above template types, the image would be exported on a file system and return absolute path.
Use the method with other template types, the image would be exported in a report output and return INVALID path.createImageWithAbsolutePath(Image image, boolean includeURI) Export image and return absolute path of the file.
This method is suitable for TXT, HTML and XML template only.
Use the method with above template types, the image would be exported on a file system and return absolute path.
Use the method with other template types, the image would be exported in a report output and return INVALID path.createImageWithRelativePath(Image image) Export image and return relative path of image file.
This method is suitable for TXT, HTML and XML template only.
Use the method with above template types, the image would be exported on a file system and return relative path.
Use the method with other template types, the image would be exported in a report output and return INVALID path.createSilentImage(Image image) Create image and do not return any path.getAbsolutePath(Image image) Return an absolute path of image file.getAbsolutePath(Image image, boolean includeURI) Return an absolute path of image file.intgetDPI()getImageProperty(Image image) Get ImageProperty objectprotected RectangleCalculate the paper bounds.protected RectanglegetPaperBounds(Image image) Calculate the paper bounds.getRelativePath(Image image) Return a possible relative path of image file.Include an external image from local file or URL into report.limitImageSize(Image image) Limit image size to paper page size.limitImageSize(Image image, int maximumWidthPixel, int maximumHeightPixel) Limit image size to paper page size and maximum size.limitImageSize(Image image, String maximumWidth, String maximumHeight) Limit image size to paper page size and maximum size.intmeasureToPixel(Image image, String measure) Transforms measurements into pixel count.intmeasureToPixel(String measure) rotateLeft(Image image) Return the image transform with clockwise rotation transformation.rotateRight(Image image) Return the image transformed with clockwise rotation transformation.Convenience method to scale equally in height and width.Return the image after scaling transformation.setDPI(int newDpi) Sets the DPI value for this document.Return the image from specified height.Return the image from specified height.Scale the image by the given height measurement, keeping the ratio.Scale the image by the given height measurement, and keep ratio if set.setScalingQuality(int quality) Sets the image scaling quality.voidsetSeparateChar(String separateChar) Set separate character for printing image path.
For example.
"/" or "\"Return the image from specified width and height.Scale the image by the given width/height measurements.Scale the image by the given width/height measurements.Return the image from specified width.Return the image from specified width.Scale the image by the given width measurements, keeping the ratio.Scale the image by the given width measurement, and keep ratio if set.Split the image into rows and columns with automatic number of rows and columns, and draw each chunked image from left-to-right and top-to-bottom.Split the image into rows and columns, and draw each chunked image from left-to-right and top-to-bottom.Methods inherited from class com.nomagic.magicreport.engine.Tool
clone, getContext, getProperties, getProperty, getProperty, notifyObservers, setContext, setPropertiesMethods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, setChanged
-
Field Details
-
CONTEXT_NAME
Contains a context name.- See Also:
-
LOWEST
public static final int LOWESTThe scaling quality lowest. Current implementation is interpolation nearest neighbor.- See Also:
-
LOW
public static final int LOWThe scaling quality low. Current implementation is one step interpolation bi-linear.- See Also:
-
MEDIUM
public static final int MEDIUMThe scaling quality medium. Current implementation is interpolation bi-cubic.- See Also:
-
HIGH
public static final int HIGHThe scaling quality high. Current implementation is multi-steps interpolation bi-linear.- See Also:
-
HIGHEST
public static final int HIGHESTThe scaling quality highest. Current implementation is area average image scaling algorithm. (Default value)- See Also:
-
PAPER_SIZE
public static final int PAPER_SIZEConstant value for paper size. Use this value to set image dimension to paper size.
Example:$image.setWidth($diagram.image, -1)- See Also:
-
DEFAULT_DPI
public static final int DEFAULT_DPIThe default DPI which is 96.- See Also:
-
REDUCE_TO_PAPER_SIZE
public static final int REDUCE_TO_PAPER_SIZEConstant value for paper size. Use this value to automatic reduce image bounds to fit the paper size if and only if image bounds is larger than the paper size.
Example:$image.setWidth($diagram.image, -2)- See Also:
-
-
Constructor Details
-
ImageTool
public ImageTool()Prevent empty initiate. -
ImageTool
Create an image tool with engine.- Parameters:
engine- default global engine
-
-
Method Details
-
setSeparateChar
Set separate character for printing image path.
For example.
"/" or "\"- Parameters:
separateChar- character for printing image path.
-
scale
Convenience method to scale equally in height and width.- Parameters:
image- the image to be scaled.sxy- the scaling factor for both height and width- Returns:
- the scaled image
- See Also:
-
scale
Return the image after scaling transformation. Subsequent rendering is resized according to the specified scaling factors relative to the previous scaling.Note: new image id is ${old.id}-${sx},${sy}
- Parameters:
image- report imagesx- the amount by which X coordinates in subsequent rendering operations are multiplied relative to previous rendering operations.sy- the amount by which Y coordinates in subsequent rendering operations are multiplied relative to previous rendering operations.- Returns:
- the image after scaling transformation.
- See Also:
-
setSize
Return the image from specified width and height.- Parameters:
image- report imagewidth- the new width for this image objectheight- the new height for this image object- Returns:
- the image with new size
- See Also:
-
setSize
Scale the image by the given width/height measurements.- Parameters:
image- the image to be scaled.width- the width as in, cm, mm, pt or pxheight- the height as in, cm, mm, pt or px- Returns:
- the scaled image
- See Also:
-
setSize
Scale the image by the given width/height measurements.- Parameters:
image- the image to be scaled.width- the width as in, cm, mm, pt or pxheight- the height as in, cm, mm, pt or pxoverrideAutoSizing- setSize function will override AutoImageResizing function when true; otherwise, AutoImageResizing option will override set size.- Returns:
- the scaled image
- See Also:
-
setWidth
Return the image from specified width. Keep image ratio when transform.- Parameters:
image- report imagewidth- the new width for this image object- Returns:
- the image with new size
-
setWidth
Return the image from specified width. If keep ratio is specified, the image will be scaled with proper ratio.- Parameters:
image- report imagewidth- the new width for this image objectkeepratio- keep image ratio when true; otherwise false- Returns:
- the image with new size
- See Also:
-
setWidth
Scale the image by the given width measurements, keeping the ratio.- Parameters:
image- the image to be scaled.width- the width as in, cm, mm, pt or px- Returns:
- the scaled image
- See Also:
-
setWidth
Scale the image by the given width measurement, and keep ratio if set.- Parameters:
image- the image to be scaled.width- the width as in, cm, mm, pt or pxkeepRatio- keeps image ratio if set to true- Returns:
- the scaled image
- See Also:
-
setHeight
Return the image from specified height. Keep image ratio when transform.- Parameters:
image- report imageheight- the new height for this image object- Returns:
- the image with new size
- See Also:
-
setHeight
Return the image from specified height. If keep ratio is specified, the image will be scaled with proper ratio.- Parameters:
image- report imageheight- the new height for this image objectkeepratio- keep image ratio when true; otherwise false- Returns:
- the image with new size
- See Also:
-
setHeight
Scale the image by the given height measurement, keeping the ratio.- Parameters:
image- the image to be scaled.height- the height as in, cm, mm, pt or px- Returns:
- the scaled image
- See Also:
-
setHeight
Scale the image by the given height measurement, and keep ratio if set.- Parameters:
image- the image to be scaled.height- the height as in, cm, mm, pt or pxkeepRatio- keeps image ratio if set to true- Returns:
- the scaled image
- See Also:
-
rotateRight
Return the image transformed with clockwise rotation transformation.- Parameters:
image- report image- Returns:
- the transformed image
- See Also:
-
rotateLeft
Return the image transform with clockwise rotation transformation.- Parameters:
image- report image- Returns:
- the transformed image
- See Also:
-
setDPI
Sets the DPI value for this document.- Parameters:
newDpi- the new dpi value, default is 96.- Returns:
- nothing
-
getDPI
public int getDPI() -
setScalingQuality
Sets the image scaling quality.- Parameters:
quality- a quality level value from 1-5;- Returns:
- nothing
- See Also:
-
measureToPixel
-
measureToPixel
Transforms measurements into pixel count.- Parameters:
measure- the measurement in inches, cm, mm or pixels- Returns:
- the measure in pixels
-
include
Include an external image from local file or URL into report.
$image.include('c:/my document/logo.gif') $image.include('http://www.magicdraw.com/images/product_boxes/MD.gif')- Parameters:
location- an image location. Location format can be either URI or system file.- Returns:
- the report image
- Throws:
MalformedURLException- invalid location format
-
copy
Copy an external image from local file or URL into report.
$image.copy('c:/my document/logo.gif') $image.copy('http://www.magicdraw.com/images/product_boxes/MD.gif')- Parameters:
location- an image location. Location format can be either URI or system file.- Returns:
- the report image
- Throws:
MalformedURLException- invalid location format
-
calculatePaperWidthHeight
protected float[] calculatePaperWidthHeight()Deprecated.seegetPaperBounds()Calculate the paper width and height.- Returns:
- array of paper width and height
-
getPaperBounds
Calculate the paper bounds.- Returns:
- the bounds of paper
-
getPaperBounds
Calculate the paper bounds.- Returns:
- the bounds of paper
-
createFormatterWrapper
Create the formatter wrapper from given engine class.- Parameters:
engineClass- the engine class- Returns:
IFormatterWrapper
-
split
Split the image into rows and columns with automatic number of rows and columns, and draw each chunked image from left-to-right and top-to-bottom.- Parameters:
image- the original image.- Returns:
- the array of splitted image order by left-to-right and top-to-bottom.
- See Also:
-
split
Split the image into rows and columns, and draw each chunked image from left-to-right and top-to-bottom. *Note:
- new image id is ${old.id};${col},${row}
- The
PAPER_SIZEwill be determined from propertyTemplateConstants.TEMPLATE_INPUT_FORMAT. - If the
PAPER_SIZEis specified but cannot be determined that specific cols or rows won't be split.
- Parameters:
image- the original image.cols- number of columns. SpecifiesPAPER_SIZEto automatic calculate number of columns from paper width.rows- number of rows. SpecifiesPAPER_SIZEto automatic calculate number of rows from paper height.- Returns:
- the array of splitted image order by left-to-right and top-to-bottom.
-
createSilentImage
Create image and do not return any path.- Parameters:
image- an image to be created- Returns:
- Void
-
createImageWithRelativePath
Export image and return relative path of image file.
This method is suitable for TXT, HTML and XML template only.
Use the method with above template types, the image would be exported on a file system and return relative path.
Use the method with other template types, the image would be exported in a report output and return INVALID path.- Parameters:
image- an image to be created- Returns:
- relative path of image file
-
createImageWithAbsolutePath
Export image and return absolute path of the file.
This method is suitable for TXT, HTML and XML template only.
Use the method with above template types, the image would be exported on a file system and return absolute path.
Use the method with other template types, the image would be exported in a report output and return INVALID path.- Parameters:
image- an image to be created- Returns:
- absolute path and image file
-
createImageWithAbsolutePath
Export image and return absolute path of the file.
This method is suitable for TXT, HTML and XML template only.
Use the method with above template types, the image would be exported on a file system and return absolute path.
Use the method with other template types, the image would be exported in a report output and return INVALID path.- Parameters:
image- an image to be createdincludeURI- true to include uri in path- Returns:
- absolute path and image file
-
getRelativePath
Return a possible relative path of image file.
This method does not export an image.
It returns a possible relative path that the image should be exported to.
This method is suitable for TXT, HTML and XML template only.
Use the method with above template types, it will return relative path.
Use the method with other template types, it will return INVALID path.- Parameters:
image- an image- Returns:
- relative path of image
-
getAbsolutePath
Return an absolute path of image file.
This method does not export an image.
It return a possible absolute path that the image should be exported to.
This method is suitable for TXT, HTML and XML template only.
Use the method with above template types, it will return absolute path.
Use the method with other template types, it will return INVALID path.- Parameters:
image- an image- Returns:
- absolute path of image
-
getAbsolutePath
Return an absolute path of image file.
This method does not export an image.
It return a possible absolute path that the image should be exported to.
This method is suitable for TXT, HTML and XML template only.
Use the method with above template types, it will return absolute path.
Use the method with other template types, it will return INVALID path.- Parameters:
image- an imageincludeURI- true to include uri in path- Returns:
- absolute path of image
-
getImageProperty
Get ImageProperty object- Parameters:
image- current image- Returns:
- image with its properties
-
limitImageSize
Limit image size to paper page size.- Parameters:
image- image- Returns:
- resized image
-
limitImageSize
Limit image size to paper page size and maximum size.- Parameters:
image- imagemaximumWidth- maximum width of image as in, cm, mm, pt or pxmaximumHeight- maximum height of image as in, cm, mm, pt or px- Returns:
- resized image
-
limitImageSize
Limit image size to paper page size and maximum size.- Parameters:
image- imagemaximumWidthPixel- maximum width of image as pixel numbermaximumHeightPixel- maximum height of image as pixel number- Returns:
- resized image
-
getPaperBounds()