Packages

 

com.aspose.imaging.fileformats.webp

Class WebPFrameBlock

    • Constructor Detail

      • WebPFrameBlock

        public WebPFrameBlock(RasterImage rasterImage)

        Initializes a new instance of the WebPFrameBlock class.

        Parameters:
        rasterImage - The raster image.
      • WebPFrameBlock

        public WebPFrameBlock(int width,
                              int height)

        Initializes a new instance of the WebPFrameBlock class.

        Parameters:
        width - The width.
        height - The height.
        Code example:

        This example shows how to create a multi-frame animated WebP image with the specified options.


        String dir = "c:\\temp\\";
        
        com.aspose.imaging.imageoptions.WebPOptions createOptions = new com.aspose.imaging.imageoptions.WebPOptions();
        createOptions.setLossless(true);
        createOptions.setQuality(100f);
        createOptions.setAnimBackgroundColor((long) com.aspose.imaging.Color.getGray().toArgb());
        
        // The default frame plus 36 + 36 additional frames.
        createOptions.setAnimLoopCount(36 + 36 + 1);
        
        // Create a WebP image of 100x100 px.
        com.aspose.imaging.fileformats.webp.WebPImage webPImage = new com.aspose.imaging.fileformats.webp.WebPImage(100, 100, createOptions);
        try {
            // The first circle is red
            com.aspose.imaging.brushes.SolidBrush brush1 = new com.aspose.imaging.brushes.SolidBrush(com.aspose.imaging.Color.getRed());
        
            // The second circle is black
            com.aspose.imaging.brushes.SolidBrush brush2 = new com.aspose.imaging.brushes.SolidBrush(com.aspose.imaging.Color.getBlack());
        
            // Gradually increase the angle of the red arc shape.
            for (int angle = 10; angle <= 360; angle += 10) {
                com.aspose.imaging.fileformats.webp.WebPFrameBlock block = new com.aspose.imaging.fileformats.webp.WebPFrameBlock(100, 100);
                com.aspose.imaging.Graphics graphics = new com.aspose.imaging.Graphics(block);
                graphics.fillPie(brush1, block.getBounds(), 0, angle);
        
                webPImage.addBlock(block);
            }
        
            // Gradually increase the angle of the black arc and wipe out the red arc.
            for (int angle = 10; angle <= 360; angle += 10) {
                com.aspose.imaging.fileformats.webp.WebPFrameBlock block = new com.aspose.imaging.fileformats.webp.WebPFrameBlock(100, 100);
        
                com.aspose.imaging.Graphics graphics = new com.aspose.imaging.Graphics(block);
                graphics.fillPie(brush2, block.getBounds(), 0, angle);
                graphics.fillPie(brush1, block.getBounds(), angle, 360 - angle);
        
                webPImage.addBlock(block);
            }
        
            // Save to a WebP file
            webPImage.save(dir + "output.webp");
        } finally {
            webPImage.dispose();
        }
        

    • Method Detail

      • getBitsPerPixel

        public int getBitsPerPixel()

        Gets the image bits per pixel count.

        Specified by:
        getBitsPerPixel in class Image
        Returns:
        The image bits per pixel count.
      • hasAlpha

        public boolean hasAlpha()

        Gets a value indicating whether this instance has alpha.

        Overrides:
        hasAlpha in class RasterImage
        Returns:
        true if this instance has alpha; otherwise, false.
        Code example:

        The following example loads a WEBP image and prints information about raw data format and alpha channel.


        String dir = "c:\\temp\\";
        String fileName = dir + "sample.webp";
        com.aspose.imaging.Image image = com.aspose.imaging.Image.load(fileName);
        try {
            com.aspose.imaging.fileformats.webp.WebPImage webpImage = (com.aspose.imaging.fileformats.webp.WebPImage) image;
        
            // If the active TIFF frame has alpha channel, then the entire TIFF image is considered to have alpha channel.
            System.out.printf("ImageFile=%s, FileFormat=%s, HasAlpha=%s\r\n", fileName, webpImage.getRawDataFormat(), webpImage.hasAlpha());
        
            int i = 0;
            for (com.aspose.imaging.fileformats.webp.IFrame frame : webpImage.getBlocks()) {
                if (frame instanceof com.aspose.imaging.fileformats.webp.WebPFrameBlock) {
                    com.aspose.imaging.fileformats.webp.WebPFrameBlock frameBlock = (com.aspose.imaging.fileformats.webp.WebPFrameBlock) frame;
                    System.out.printf("Frame=%s, FileFormat=%s, HasAlpha=%s\r\n", i++, frameBlock.getRawDataFormat(), frameBlock.hasAlpha());
                }
            }
        } finally {
            image.dispose();
        }
        
        // The output may look like this:
        // ImageFile=c:\temp\sample.webp, FileFormat=RgbIndexed1Bpp, used channels: 1, HasAlpha=False
        // Frame=0, FileFormat=RgbIndexed1Bpp, used channels: 1, HasAlpha=False
        

      • getDuration

        public short getDuration()

        Gets or sets the frame duration.

        Specified by:
        getDuration in interface IFrame
        Returns:
        The duration.
      • setDuration

        public void setDuration(short value)

        Gets or sets the frame duration.

        Specified by:
        setDuration in interface IFrame
        Parameters:
        value - The duration.
      • getLeft

        public short getLeft()

        Gets or sets the frame position left.

        Specified by:
        getLeft in interface IFrame
        Returns:
        The left.
      • setLeft

        public void setLeft(short value)

        Gets or sets the frame position left.

        Specified by:
        setLeft in interface IFrame
        Parameters:
        value - The left.
      • getTop

        public short getTop()

        Gets or sets the frame position top.

        Specified by:
        getTop in interface IFrame
        Returns:
        The top.
      • setTop

        public void setTop(short value)

        Gets or sets the frame position top.

        Specified by:
        setTop in interface IFrame
        Parameters:
        value - The top.
      • getFrameTime

        public final int getFrameTime()

        Gets the duration.

        Value: The duration. <autogeneratedoc></autogeneratedoc>
        Specified by:
        getFrameTime in interface IAnimationFrame
        Returns:
        the duration.
      • getFrameTop

        public final int getFrameTop()

        Converts to p.

        Value: The top. <autogeneratedoc></autogeneratedoc>
        Specified by:
        getFrameTop in interface IAnimationFrame
      • getFrameLeft

        public final int getFrameLeft()

        Gets the left.

        Value: The left. <autogeneratedoc></autogeneratedoc>
        Specified by:
        getFrameLeft in interface IAnimationFrame
        Returns:
        the left.