Class Image

java.lang.Object
com.nomagic.magicreport.Image
All Implemented Interfaces:
IObserverMessage, IVariable, Serializable, Cloneable
Direct Known Subclasses:
ReportSVGIcon, SVGIcon

@OpenApiAll public class Image extends Object implements IObserverMessage, IVariable, Cloneable
An bean represent image object for template. If dispose was set, the engine will dispose image data after image has been exported to report.
Since:
Jul 2, 2007
See Also:
  • Field Details

    • FIT_PAPER

      public static final int FIT_PAPER
      Constants bit for image transformation (auto fit).
      See Also:
    • MAINTAIN_RATIO

      public static final int MAINTAIN_RATIO
      Constants bit for image transformation (maintain ratio).
      See Also:
    • ROTATE_LEFT

      public static final int ROTATE_LEFT
      Constants bit for image transformation (rotate left).
      See Also:
    • ROTATE_RIGHT

      public static final int ROTATE_RIGHT
      Constants bit for image transformation (rotate right).
      See Also:
    • LARGE_ONLY

      public static final int LARGE_ONLY
      Constants bit for image transformation (perform operation only when image is large only).
      See Also:
    • IMAGE_TYPE_IMAGE

      public static final int IMAGE_TYPE_IMAGE
      Constants for image type that is created as icon or image
      See Also:
    • IMAGE_TYPE_ICON

      public static final int IMAGE_TYPE_ICON
      See Also:
    • TRUE_TRANSFORM

      public static final int TRUE_TRANSFORM
      Constants bit for image transformation (physically transform image instead of use document feature).
      See Also:
    • FORCE_ROTATE_LEFT

      public static final int FORCE_ROTATE_LEFT
      Constants bit for force rotate (rotate left).
      See Also:
    • FORCE_ROTATE_RIGHT

      public static final int FORCE_ROTATE_RIGHT
      Constants bit for force rotate (rotate right).
      See Also:
    • FORCE_ROTATE

      public static final int FORCE_ROTATE
      Constants bit for force rotate
      See Also:
  • Constructor Details

    • Image

      public Image(String id, File imageFile, boolean disposeAfterUse)
      Create a new image from file. If disposeAfterUse is true, image will be disposed immediately after print into report.

      Generally, same image will be used only once in the template, it's recommend to set disposeAfterUse to true.

      Parameters:
      id - image id
      imageFile - image file.
      disposeAfterUse - if true, dispose an image after use.
      Throws:
      IllegalArgumentException - if image file is null
    • Image

      public Image(String id, BufferedImage data, String imageFormat, boolean disposeAfterUse)
      Create a new image from buffered image. If disposeAfterUse is true, image will be disposed immediately after print into report.

      Generally, same image will be used only once in the template, it's recommend to set disposeAfterUse to true.

      data can be null.

      Parameters:
      id - image id
      data - the image data
      imageFormat - the image format.
      disposeAfterUse - if true, dispose an image after use.
      Throws:
      IllegalArgumentException - if image format is null
  • Method Details

    • getProperties

      public Map<String,Object> getProperties()
    • setProperties

      public void setProperties(Map<String,Object> properties)
    • setOriginalImageFile

      public void setOriginalImageFile(File originalImageFile)
    • setOriginalWidth

      public void setOriginalWidth(int originalWidth)
    • setOriginalHeight

      public void setOriginalHeight(int originalHeight)
    • getId

      public String getId()
      Return a id.
      Returns:
      the id
    • setId

      public void setId(String id)
      Set a id.
      Parameters:
      id - the id to set
    • getName

      public String getName()
      Return a name.
      Specified by:
      getName in interface IObserverMessage
      Returns:
      the name
    • setName

      public void setName(String name)
      Set a name.
      Parameters:
      name - the name to set
    • getData

      public BufferedImage getData()
      Return a data.
      Returns:
      the data
    • setData

      public void setData(BufferedImage data)
      Set a data.
      Parameters:
      data - the data to set
    • getImageFormat

      public String getImageFormat()
      Return an image format.
      Returns:
      the image format
    • setImageFormat

      public void setImageFormat(String imageFormat)
      Set an image format.
      Parameters:
      imageFormat - the image format to set
    • getOriginalImageFormat

      public String getOriginalImageFormat()
      Return an original image format. For external image file, it may have real format that different to file extension
      Returns:
      the original image format
    • setOriginalImageFormat

      public void setOriginalImageFormat(String originalImageFormat)
      Set an original image format. For external image file, it may have real format that different to file extension
      Parameters:
      originalImageFormat - the original image format to set
    • setProperty

      public void setProperty(String key, Object value)
      Set an image property.
      Parameters:
      key - the key to be placed into this property list.
      value - the value corresponding to key.
    • getProperty

      public Object getProperty(String key)
      Searches for the property with the specified key in this property list. The method returns null if the property is not found.
      Parameters:
      key - the property key.
      Returns:
      the value in this property list with the specified key value.
      See Also:
    • isChanged

      public boolean isChanged()
      Return a changed.
      Returns:
      the changed
    • setChanged

      public void setChanged(boolean changed)
      If false, dispose image buffer and mark a status. Developer should detect an image status before retrieve a new buffer from getData().
      Parameters:
      changed - the changed to set
      See Also:
    • readData

      public BufferedImage readData()
      Read a buffered image from this instance. Return BufferedImage if getData() contains data or read from getImageFile().
      Returns:
      a buffered image from getData() or getImageFile()
    • flush

      public void flush() throws IOException
      Flush current buffered image from getData() into file stream. This method will set a new image file and dispose the data. The image file will be deleted when this object is garbage collected.
      Throws:
      IOException - when unable to flush the data.
      See Also:
    • flush

      public void flush(Object track) throws IOException
      Flush current buffered image from getData() into file stream. This method will set a new image file and dispose the data. The image file will be deleted when tracked object is garbage collected.
      Parameters:
      track - the marker object track flushed file, deleting the file when the marker instance is garbage collected.
      Throws:
      IOException - when unable to flush the data.
      See Also:
    • dispose

      public void dispose()
      Disposes of this image buffer context and releases any system resources that it is using.
    • getSize

      public int getSize()
      Returns the size of image in pixels.
      Returns:
      the size of image in pixels.
    • getBounds

      public Rectangle getBounds()
      Returns the bounding Rectangle of this Image.

      If image contains no data buffer readData() return null, the bounds will be calculated from getWidth() and getHeight().
      If image contains buffer data, calculate the bounds from buffer data.

      Returns:
      the bounding box of this image.
    • setWidth

      public void setWidth(int width)
      Set width of image in pixels.
      Parameters:
      width - width of image
    • getWidth

      public int getWidth()
      Return the width of image in pixels.
      Returns:
      the width of image in pixels
    • setHeight

      public void setHeight(int height)
      Set height of image in pixels.
      Parameters:
      height - height of image in pixels
    • getHeight

      public int getHeight()
      Return the height of image in pixels.
      Returns:
      the height of image in pixels
    • getImageFile

      public File getImageFile()
      Return a imageFile.
      Returns:
      the imageFile
    • setImageFile

      public void setImageFile(File imageFile)
      Set a imageFile.
      Parameters:
      imageFile - the imageFile to set
    • isDisposeAfterUse

      public boolean isDisposeAfterUse()
      Return a dispose setting.
      Returns:
      the dispose setting
    • setDisposeAfterUse

      public void setDisposeAfterUse(boolean disposeAfterUse)
      Set image data to be disposed after generating report.
      Parameters:
      disposeAfterUse - set value to true to allow engine to dispose image data.
    • getOriginalImageFile

      public File getOriginalImageFile()
      Return an original image file.
      Returns:
      the original image file
    • getOriginalWidth

      public int getOriginalWidth()
      Return a original width.
      Returns:
      the original width
    • getOriginalHeight

      public int getOriginalHeight()
      Return a original height.
      Returns:
      the original height
    • getOriginalBounds

      public Rectangle getOriginalBounds()
      Returns the original bounding Rectangle of this Image.
      Returns:
      the original bounding box of this image.
    • getTransformationOption

      public int getTransformationOption()
      Return a transformation flag.
      Returns:
      the transformation flag
    • setTransformationOption

      public void setTransformationOption(int transformationOption)
      Set a transformation option.
      Parameters:
      transformationOption - the transformation option to set
    • isTransformWithOption

      public boolean isTransformWithOption(int option)
      Test if image transformation option is set to given option.
      Parameters:
      option - test option
      Returns:
      true if image transformation option is set to given option.
    • rotate

      public void rotate(boolean clockwise)
      Rotate image in clockwise or anti-clockwise.
      Parameters:
      clockwise - true for clockwise; false for anti-clockwise
    • createOriginal

      public Image createOriginal()
      Create a new instance of original image.
      Returns:
      a new instance of original image.
    • ensureOriginal

      public void ensureOriginal()
    • hashCode

      public int hashCode()
      Returns a hash code value for the object.
      Overrides:
      hashCode in class Object
      Returns:
      a hash code value for this object.
      See Also:
    • equals

      public boolean equals(Object obj)
      Indicates whether some other object is "equal to" this one.
      Overrides:
      equals in class Object
      Parameters:
      obj - the reference object with which to compare.
      Returns:
      true if this object is the same as the obj argument; false otherwise.
      See Also:
    • clone

      public Object clone() throws CloneNotSupportedException
      Creates and returns a copy of this object.
      Overrides:
      clone in class Object
      Returns:
      a copy of this instance
      Throws:
      CloneNotSupportedException - if the object's class does not support the Cloneable interface.
      See Also:
    • toString

      public String toString()
      Returns a string representation of the object.
      Overrides:
      toString in class Object
      Returns:
      a string representation of the object.
    • getImageType

      public int getImageType()
      Get image type. For example : icon image from $report.getIconFor(), image from $element.image
      Returns:
      image type
    • setImageType

      public void setImageType(int imageType)
      Set image type. For example : icon image from $report.getIconFor(), image from $element.image
      Parameters:
      imageType - image type
    • getImageFormatToWrite

      public String getImageFormatToWrite()
    • getDpi

      public int getDpi()
    • setDpi

      public void setDpi(int dpi)