Packages

 

com.aspose.imaging.fileformats.wmf

Class WmfImage

  • All Implemented Interfaces:
    IObjectWithBounds, com.aspose.imaging_internal.progressmanagement.IProgressEventHandler, com.aspose.imaging_internal.progressmanagement.IProgressInformer, com.aspose.ms.System.IDisposable, Closeable, AutoCloseable


    public class WmfImage
    extends MetaImage

    The Wmf Image

    • Constructor Detail

      • WmfImage

        public WmfImage()

        Initializes a new instance of the WmfImage class.

      • WmfImage

        public WmfImage(int width,
                        int height)

        Initializes a new instance of the WmfImage class.

        Parameters:
        width - The width.
        height - The height.
    • Method Detail

      • isCached

        public boolean isCached()

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

        Specified by:
        isCached in class DataStreamSupporter
        Returns:
        true if object's data is cached; otherwise, false.
        Throws:
        com.aspose.ms.System.NotImplementedException - Value: true if object's data is cached; otherwise, false.
      • getBitsPerPixel

        public int getBitsPerPixel()

        Gets the image bits per pixel count.

        Specified by:
        getBitsPerPixel in class Image
        Returns:
        The image bits per pixel count.
        Throws:
        com.aspose.ms.System.NotImplementedException - Value: The image bits per pixel count.
      • getWidth

        public int getWidth()

        Gets the image width.

        Specified by:
        getWidth in interface IObjectWithBounds
        Specified by:
        getWidth in class Image
        Returns:
        The image width.
        Throws:
        com.aspose.ms.System.NotImplementedException - Value: The image width.
      • getHeight

        public int getHeight()

        Gets the image height.

        Specified by:
        getHeight in interface IObjectWithBounds
        Specified by:
        getHeight in class Image
        Returns:
        The image height.
        Throws:
        com.aspose.ms.System.NotImplementedException - Value: The image height.
      • getInch

        public int getInch()

        Gets or sets the inch.

        Value: The inch.
      • setInch

        public void setInch(int value)

        Gets or sets the inch.

        Value: The inch.
      • getFileFormat

        public long getFileFormat()

        Gets a value of file format

        Overrides:
        getFileFormat in class Image
      • getFrameBounds

        public final Rectangle getFrameBounds()

        Gets the frame bounds.

        Value: The frame bounds.
        Returns:
        the frame bounds.
      • 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
        Throws:
        com.aspose.ms.System.NotImplementedException - this feature is not implemented
        Code example:

        This example shows how to load a WMF image from a file and list all of its records.


        String dir = "c:\\temp\\";
        
        // Using Aspose.Imaging.Image.Load is a unified way to load all types of images including WMF.
        com.aspose.imaging.fileformats.wmf.WmfImage wmfImage = (com.aspose.imaging.fileformats.wmf.WmfImage) com.aspose.imaging.Image.load(dir + "test.wmf");
        try {
            // Cache data to load all records.
            wmfImage.cacheData();
            System.out.println("The total number of records: " + wmfImage.getRecords().size());
        
            // The key is a record type, the value is number of records of that type in the WMF image.
            java.util.HashMap<Class, Integer> types = new java.util.HashMap<>();
        
            // Gather statistics
            for (Object obj : wmfImage.getRecords()) {
                com.aspose.imaging.fileformats.wmf.objects.WmfObject wmfObj = (com.aspose.imaging.fileformats.wmf.objects.WmfObject) obj;
        
                Class objType = wmfObj.getClass();
                if (!types.containsKey(objType)) {
                    types.put(objType, 1);
                } else {
                    int n = types.get(objType);
                    types.put(objType, n + 1);
                }
            }
        
            // Print statistics
            System.out.println("Record Type                              Count");
            System.out.println("----------------------------------------------");
            for (java.util.Map.Entry<Class, Integer> entry : types.entrySet()) {
                String objectType = entry.getKey().getSimpleName();
                int numberOfEntrances = entry.getValue();
        
                // Align output with spaces
                int alignmentPos = 40;
                char[] chars = new char[alignmentPos - objectType.length()];
                java.util.Arrays.fill(chars, ' ');
                String gap = new String(chars);
        
                System.out.println(objectType + ":" + gap + numberOfEntrances);
            }
        } finally {
            wmfImage.dispose();
        }
        
        //The output may look like this:
        //The total number of records: 613
        //Record Type                              Count
        //----------------------------------------------
        //WmfSetBkMode:                            1
        //WmfSetTextAlign:                         1
        //WmfSetRop2:                              1
        //WmfSetWindowOrg:                         1
        //WmfSetWindowExt:                         1
        //WmfCreateBrushInDirect:                  119
        //WmfSelectObject:                         240
        //WmfCreatePenInDirect:                    119
        //WmfSetPolyFillMode:                      1
        //WmfPolyPolygon:                          114
        //WmfPolyLine:                             7
        //WmfSetTextColor:                         2
        //WmfCreateFontInDirect:                   2
        //WmfExtTextOut:                           2
        //WmfDibStrechBlt:                         1
        //WmfEof:                                  1
        

      • 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
        Code example:

        This example loads a WMF image and resizes it using various resizing methods.


        String dir = "c:\\temp\\";
        
        com.aspose.imaging.fileformats.wmf.WmfImage image = (com.aspose.imaging.fileformats.wmf.WmfImage) com.aspose.imaging.Image.load(dir + "sample.wmf");
        try {
            // Scale up by 2 times using Nearest Neighbour resampling.
            image.resize(image.getWidth() * 2, image.getHeight() * 2, com.aspose.imaging.ResizeType.NearestNeighbourResample);
        } finally {
            image.dispose();
        }
        
        image = (com.aspose.imaging.fileformats.wmf.WmfImage) com.aspose.imaging.Image.load(dir + "sample.wmf");
        try {
            // Scale down by 2 times using Nearest Neighbour resampling.
            image.resize(image.getWidth() / 2, image.getHeight() / 2, com.aspose.imaging.ResizeType.NearestNeighbourResample);
        } finally {
            image.dispose();
        }
        
        image = (com.aspose.imaging.fileformats.wmf.WmfImage) com.aspose.imaging.Image.load(dir + "sample.wmf");
        try {
            // Scale up by 2 times using Bilinear resampling.
            image.resize(image.getWidth() * 2, image.getHeight() * 2, com.aspose.imaging.ResizeType.BilinearResample);
        } finally {
            image.dispose();
        }
        
        image = (com.aspose.imaging.fileformats.wmf.WmfImage) com.aspose.imaging.Image.load(dir + "sample.wmf");
        try {
            // Scale down by 2 times using Bilinear resampling.
            image.resize(image.getWidth() / 2, image.getHeight() / 2, com.aspose.imaging.ResizeType.BilinearResample);
        } finally {
            image.dispose();
        }
        

      • 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 - this feature is not implemented
      • getUsedFonts

        public String[] getUsedFonts()

        Returns the list of font which used inside metafile.

        Specified by:
        getUsedFonts in class MetaImage
        Returns:
        The font list
      • crop

        public void crop(Rectangle rectangle)

        Crops the specified rectangle.

        Overrides:
        crop in class MetaImage
        Parameters:
        rectangle - The rectangle.
      • resizeCanvas

        public void resizeCanvas(Rectangle newRectangle)

        Resizes the canvas.

        Specified by:
        resizeCanvas in class MetaImage
        Parameters:
        newRectangle - The new rectangle.
      • addRecord

        public int addRecord(WmfObject record)

        Adds the record.

        Parameters:
        record - The record.
        Returns:
        Number of record.
      • getPostScript

        public final String getPostScript()

        Gets the post script.

        Returns:
        The post script