Packages

 

com.aspose.imaging.fileformats.svg

Class SvgImage

  • All Implemented Interfaces:
    IObjectWithBounds, com.aspose.ms.System.IDisposable, Closeable, AutoCloseable


    public final class SvgImage
    extends Image

    Represents SVG image class.

    Code example:

    This example shows how to load an SVG image from a file stream and rasterize it to PNG.


    String dir = "c:\\temp\\";
    
    // Load an SVG image from a file stream.
    java.io.InputStream stream = new java.io.FileInputStream(dir + "test.svg");
    com.aspose.imaging.fileformats.svg.SvgImage svgImage = new com.aspose.imaging.fileformats.svg.SvgImage(stream);
    try {
        // In order to rasterize SVG we need to specify rasterization options.
        com.aspose.imaging.imageoptions.SvgRasterizationOptions rasterizationOptions = new com.aspose.imaging.imageoptions.SvgRasterizationOptions();
        com.aspose.imaging.imageoptions.PngOptions saveOptions = new com.aspose.imaging.imageoptions.PngOptions();
        saveOptions.setVectorRasterizationOptions(rasterizationOptions);
    
        svgImage.save(dir + "test.output.png", saveOptions);
    } finally {
        svgImage.dispose();
        stream.close();
    }
    

    • Constructor Detail

      • SvgImage

        public SvgImage(String path)

        Initializes a new instance of the SvgImage class.

        Parameters:
        path - The path to load image from and initialize pixel and palette data with.
        Throws:
        com.aspose.ms.System.ArgumentNullException - path is null.
      • SvgImage

        public SvgImage(InputStream stream)

        Initializes a new instance of the SvgImage class.

        Parameters:
        stream - The stream to load image from and initialize pixel and palette data with.
        Throws:
        com.aspose.ms.System.ArgumentNullException - stream is null.
        Code example:

        This example shows how to load an SVG image from a file stream and rasterize it to PNG.


        String dir = "c:\\temp\\";
        
        // Load an SVG image from a file stream.
        java.io.InputStream stream = new java.io.FileInputStream(dir + "test.svg");
        com.aspose.imaging.fileformats.svg.SvgImage svgImage = new com.aspose.imaging.fileformats.svg.SvgImage(stream);
        try {
            // In order to rasterize SVG we need to specify rasterization options.
            com.aspose.imaging.imageoptions.SvgRasterizationOptions rasterizationOptions = new com.aspose.imaging.imageoptions.SvgRasterizationOptions();
            com.aspose.imaging.imageoptions.PngOptions saveOptions = new com.aspose.imaging.imageoptions.PngOptions();
            saveOptions.setVectorRasterizationOptions(rasterizationOptions);
        
            svgImage.save(dir + "test.output.png", saveOptions);
        } finally {
            svgImage.dispose();
            stream.close();
        }
        

      • SvgImage

        public SvgImage(int width,
                        int height)

        Initializes a new instance of the SvgImage class.

        Parameters:
        width - The image width.
        height - The image height.
      • SvgImage

        public SvgImage(SvgOptions svgOptions,
                        int width,
                        int height)

        Initializes a new instance of the SvgImage class.

        Parameters:
        svgOptions - The SVG options.
        width - Image width.
        height - Image height.
    • Method Detail

      • isCached

        public boolean isCached()

        Gets a value indicating whether object's data is cached currently and no data reading is required.

        Specified by:
        isCached in class DataStreamSupporter
        Returns:
        true if object's data is cached; otherwise, false.
      • getBitsPerPixel

        public int getBitsPerPixel()

        Gets the image bits per pixel count this parameter is not applicable to vector images

        Specified by:
        getBitsPerPixel in class Image
        Returns:
        The image bits per pixel count.
        Throws:
        com.aspose.ms.System.NotImplementedException - Not valid for vector images
      • getFileFormat

        public long getFileFormat()

        Gets a value of file format

        Overrides:
        getFileFormat in class Image
        Returns:
        file format
      • cacheData

        public void cacheData()

        Caches the data and ensures no additional data loading will be performed from the underlying DataStreamSupporter.DataStreamContainer.

        Specified by:
        cacheData in class DataStreamSupporter
      • resize

        public void resize(int newWidth,
                           int newHeight,
                           int resizeType)

        Resizes the image.

        Specified by:
        resize in class Image
        Parameters:
        newWidth - The new width.
        newHeight - The new height.
        resizeType - The resize type.
        Throws:
        com.aspose.ms.System.NotImplementedException - this feature is not implemented
      • resize

        public void resize(int newWidth,
                           int newHeight,
                           ImageResizeSettings settings)

        Resizes the image.

        Specified by:
        resize in class Image
        Parameters:
        newWidth - The new width.
        newHeight - The new height.
        settings - The resize settings.
        Throws:
        com.aspose.ms.System.NotImplementedException - this feature is not implemented
      • rotateFlip

        public void rotateFlip(int rotateFlipType)

        Rotates, flips, or rotates and flips the image.

        Specified by:
        rotateFlip in class Image
        Parameters:
        rotateFlipType - Type of the rotate flip.
        Throws:
        com.aspose.ms.System.NotImplementedException - this feature is not implemented
      • setPalette

        public void setPalette(IColorPalette palette,
                               boolean updateColors)

        Sets the image palette.

        Specified by:
        setPalette in class Image
        Parameters:
        palette - The palette to set.
        updateColors - if set to true colors will be updated according to the new palette; otherwise color indexes remain unchanged. Note that unchanged indexes may crash the image on loading if some indexes have no corresponding palette entries.
        Throws:
        com.aspose.ms.System.NotImplementedException - if not implemented