Package ej.microvg

## Class VectorImage

- java.lang.Object
- - ej.microvg.VectorImage

- Direct Known Subclasses:
    `ResourceVectorImage`

      public class VectorImage
      extends Object

  Represents a vector image.

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `VectorImage()` |

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `ResourceVectorImage` | `filterImage​(float[] colorMatrix)` | Creates an image derived from this image, applying the given color matrix.
    `long` | `getDuration()` | Gets the duration of the vector image animation if the image is animated, otherwise 0.
    `float` | `getHeight()` | Gets the height of the vector image.
    `static VectorImage` | `getImage​(String resourcePath)` | Gets a vector image from a path.
    `float` | `getWidth()` | Gets the width of the vector image.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### VectorImage

          public VectorImage()

  - ### Method Detail

    - #### getImage

          public static VectorImage getImage​(String resourcePath)

      Gets a vector image from a path.

      This method can only retrieve images which are in the internal image format defined by the MicroVG implementation. This operation does not require a dynamic allocation in order to store the image paths.

      If the resource cannot be retrieved, a `VectorGraphicsException` is thrown even if the resource is present but requires a loading step.

      Parameters:
        `resourcePath` - the path to get the image from
      Returns:
        a vector image
      Throws:
        `VectorGraphicsException` - if the image could not be retrieved for any reason (see `VectorGraphicsException.getErrorCode()`)

    - #### filterImage

          public ResourceVectorImage filterImage​(float[] colorMatrix)

      Creates an image derived from this image, applying the given color matrix.

      The returned image is allocated dynamically and must be closed explicitly.

      The given matrix is a 4x5 color matrix. It is organized like that:

      - Each line is used to compute a component of the resulting color, in this order: red, green, blue, alpha.
      - The four first columns are multipliers applied to a component of the initial color, in this order: red, green, blue, alpha.
      - The last column is a constant value.
      Each component is then computed like that: `redMultiplier x redInitialComponent + greenMultiplier x greenInitialComponent + blueMultiplier x blueInitialComponent + constant` Each component is clamped between 0x0 and 0xff.

      Let A, R, G, B be the components of the initial color and the following array a color matrix:

           { rR, rG, rB, rA, rC,
             gR, gG, gB, gA, gC,
             bR, bG, bB, bA, bC,
             aR, aG, aB, aA, aC }

      The resulting color components are computed as:

           resultRed = rR * R + rG * G + rB * B + rA * A + rC
           resultGreen = gR * R + gG * G + gB * B + gA * A + gC
           resultBlue = bR * R + bG * G + bB * B + bA * A + bC
           resultAlpha = aR * R + aG * G + aB * B + aA * A + aC

      Parameters:
        `colorMatrix` - the color matrix used to transform colors
      Returns:
        the filtered image
      Throws:
        `ArrayIndexOutOfBoundsException` - if the given color matrix is shorter than 20 entries
        `VectorGraphicsException` - if the image has overlapping paths and the color matrix puts a non-opaque alpha level

    - #### getWidth

          public float getWidth()

      Gets the width of the vector image.
      Returns:
        the width

    - #### getHeight

          public float getHeight()

      Gets the height of the vector image.
      Returns:
        the height

    - #### getDuration

          public long getDuration()

      Gets the duration of the vector image animation if the image is animated, otherwise 0.
      Returns:
        the duration of the animation of the vector image