Packages

 

com.aspose.imaging

Interfaces

Classes

Exceptions

com.aspose.imaging

Class Cache



  • public final class Cache
    extends Object

    Contains cache settings.

    Code example:

    This example demonstrates how to use com.aspose.imaging.Cache


    // By default the cache folder is set to user's local temp directory.
    // You can also specify another cache folder than default like the following:
    // com.aspose.imaging.Cache.setCacheFolder("C:\\Temp");
    
    // Auto mode is flexible and efficient
    com.aspose.imaging.Cache.setCacheType(com.aspose.imaging.CacheType.Auto);
    
    // Default value is 0, which means there is no upper limit
    com.aspose.imaging.Cache.setMaxDiskSpaceForCache(1073741824); // 1 gigabyte
    com.aspose.imaging.Cache.setMaxMemoryForCache(1073741824); // 1 gigabyte
    
    // It is not recommended to change the following property as it may greatly affect the performance
    com.aspose.imaging.Cache.setExactReallocateOnly(false);
    
    // At any time you may check how many bytes currently allocated for memory or disk
    // cache by examining the following properties
    long l1 = com.aspose.imaging.Cache.getAllocatedDiskBytesCount();
    long l2 = com.aspose.imaging.Cache.getAllocatedMemoryBytesCount();
    
    System.out.println("Initial values.");
    System.out.println("Allocated disk space, in bytes: " + l1);
    System.out.println("Allocated memory, in bytes: " + l2);
    System.out.println("--------------------------------------");
    
    // Do some image processing as below
    com.aspose.imaging.imageoptions.GifOptions options = new com.aspose.imaging.imageoptions.GifOptions();
    options.setPalette(new com.aspose.imaging.ColorPalette(
            new com.aspose.imaging.Color[]
                    {
                            com.aspose.imaging.Color.getRed(),
                            com.aspose.imaging.Color.getBlue(),
                            com.aspose.imaging.Color.getBlack(),
                            com.aspose.imaging.Color.getWhite()
                    }));
    options.setSource(new com.aspose.imaging.sources.StreamSource(new com.aspose.imaging.system.io.MemoryStream(), true));
    com.aspose.imaging.RasterImage image = (com.aspose.imaging.RasterImage) com.aspose.imaging.Image.create(options, 100, 100);
    try {
        com.aspose.imaging.Color[] pixels = new com.aspose.imaging.Color[10000];
        for (int i = 0; i < pixels.length; i++) {
            pixels[i] = com.aspose.imaging.Color.getWhite();
        }
    
        System.out.println("Set the white color for 10000 pixels.");
        image.savePixels(image.getBounds(), pixels);
    
        // After executing the code above there will be allocated 40000 bytes in-memory.
        long diskBytes = com.aspose.imaging.Cache.getAllocatedDiskBytesCount();
        long memoryBytes = com.aspose.imaging.Cache.getAllocatedMemoryBytesCount();
        System.out.println("Allocated disk space, in bytes: " + diskBytes);
        System.out.println("Allocated memory, in bytes: " + memoryBytes);
        System.out.println("--------------------------------------");
    } finally {
        System.out.println("Dispose image.");
        image.dispose();
    }
    
    // The allocation properties may be used to check whether all Aspose.Imaging objects were properly disposed.
    // In case you've forgot to call dispose on some object the cache values will be different than 0.
    l1 = com.aspose.imaging.Cache.getAllocatedDiskBytesCount();
    l2 = com.aspose.imaging.Cache.getAllocatedMemoryBytesCount();
    System.out.println("Allocated disk space, in bytes: " + l1);
    System.out.println("Allocated memory, in bytes: " + l2);
    System.out.println("--------------------------------------");
    

    • Method Detail

      • getExactReallocateOnly

        public static boolean getExactReallocateOnly()

        Gets a value indicating whether reallocation should be exact or not. If reallocation is non exact the performance should be higher.

        Returns:
        true if reallocation is exact; otherwise, false.

        The exact reallocation will perform reallocation of additional memory only up to the upper limit specified. When passing upper limit for in-memory during reallocation the cached data will be copied to disk if possible. When passing upper limit for disk memory during reallocation the appropriate exception is thrown. The performance should be higher if this option is turned off as no additional copying will be performed if possible, however this may also lead to pass upper limits specified for memory or disk.

      • setExactReallocateOnly

        public static void setExactReallocateOnly(boolean value)

        Sets a value indicating whether reallocation should be exact or not. If reallocation is non exact the performance should be higher.

        Parameters:
        value - true if reallocation is exact; otherwise, false.

        The exact reallocation will perform reallocation of additional memory only up to the upper limit specified. When passing upper limit for in-memory during reallocation the cached data will be copied to disk if possible. When passing upper limit for disk memory during reallocation the appropriate exception is thrown. The performance should be higher if this option is turned off as no additional copying will be performed if possible, however this may also lead to pass upper limits specified for memory or disk.

        Code example:

        This example demonstrates how to use com.aspose.imaging.Cache


        // By default the cache folder is set to user's local temp directory.
        // You can also specify another cache folder than default like the following:
        // com.aspose.imaging.Cache.setCacheFolder("C:\\Temp");
        
        // Auto mode is flexible and efficient
        com.aspose.imaging.Cache.setCacheType(com.aspose.imaging.CacheType.Auto);
        
        // Default value is 0, which means there is no upper limit
        com.aspose.imaging.Cache.setMaxDiskSpaceForCache(1073741824); // 1 gigabyte
        com.aspose.imaging.Cache.setMaxMemoryForCache(1073741824); // 1 gigabyte
        
        // It is not recommended to change the following property as it may greatly affect the performance
        com.aspose.imaging.Cache.setExactReallocateOnly(false);
        
        // At any time you may check how many bytes currently allocated for memory or disk
        // cache by examining the following properties
        long l1 = com.aspose.imaging.Cache.getAllocatedDiskBytesCount();
        long l2 = com.aspose.imaging.Cache.getAllocatedMemoryBytesCount();
        
        System.out.println("Initial values.");
        System.out.println("Allocated disk space, in bytes: " + l1);
        System.out.println("Allocated memory, in bytes: " + l2);
        System.out.println("--------------------------------------");
        
        // Do some image processing as below
        com.aspose.imaging.imageoptions.GifOptions options = new com.aspose.imaging.imageoptions.GifOptions();
        options.setPalette(new com.aspose.imaging.ColorPalette(
                new com.aspose.imaging.Color[]
                        {
                                com.aspose.imaging.Color.getRed(),
                                com.aspose.imaging.Color.getBlue(),
                                com.aspose.imaging.Color.getBlack(),
                                com.aspose.imaging.Color.getWhite()
                        }));
        options.setSource(new com.aspose.imaging.sources.StreamSource(new com.aspose.imaging.system.io.MemoryStream(), true));
        com.aspose.imaging.RasterImage image = (com.aspose.imaging.RasterImage) com.aspose.imaging.Image.create(options, 100, 100);
        try {
            com.aspose.imaging.Color[] pixels = new com.aspose.imaging.Color[10000];
            for (int i = 0; i < pixels.length; i++) {
                pixels[i] = com.aspose.imaging.Color.getWhite();
            }
        
            System.out.println("Set the white color for 10000 pixels.");
            image.savePixels(image.getBounds(), pixels);
        
            // After executing the code above there will be allocated 40000 bytes in-memory.
            long diskBytes = com.aspose.imaging.Cache.getAllocatedDiskBytesCount();
            long memoryBytes = com.aspose.imaging.Cache.getAllocatedMemoryBytesCount();
            System.out.println("Allocated disk space, in bytes: " + diskBytes);
            System.out.println("Allocated memory, in bytes: " + memoryBytes);
            System.out.println("--------------------------------------");
        } finally {
            System.out.println("Dispose image.");
            image.dispose();
        }
        
        // The allocation properties may be used to check whether all Aspose.Imaging objects were properly disposed.
        // In case you've forgot to call dispose on some object the cache values will be different than 0.
        l1 = com.aspose.imaging.Cache.getAllocatedDiskBytesCount();
        l2 = com.aspose.imaging.Cache.getAllocatedMemoryBytesCount();
        System.out.println("Allocated disk space, in bytes: " + l1);
        System.out.println("Allocated memory, in bytes: " + l2);
        System.out.println("--------------------------------------");
        

      • getCacheFolder

        public static String getCacheFolder()

        Gets the cache folder.

        Returns:
        The cache folder.
      • setCacheFolder

        public static void setCacheFolder(String value)

        Sets the cache folder.

        Parameters:
        value - The cache folder.
      • getAllocatedMemoryBytesCount

        public static long getAllocatedMemoryBytesCount()

        Gets the allocated in-memory bytes count.

        Returns:
        The allocated in-memory bytes count.
        Code example:

        This example demonstrates how to use com.aspose.imaging.Cache


        // By default the cache folder is set to user's local temp directory.
        // You can also specify another cache folder than default like the following:
        // com.aspose.imaging.Cache.setCacheFolder("C:\\Temp");
        
        // Auto mode is flexible and efficient
        com.aspose.imaging.Cache.setCacheType(com.aspose.imaging.CacheType.Auto);
        
        // Default value is 0, which means there is no upper limit
        com.aspose.imaging.Cache.setMaxDiskSpaceForCache(1073741824); // 1 gigabyte
        com.aspose.imaging.Cache.setMaxMemoryForCache(1073741824); // 1 gigabyte
        
        // It is not recommended to change the following property as it may greatly affect the performance
        com.aspose.imaging.Cache.setExactReallocateOnly(false);
        
        // At any time you may check how many bytes currently allocated for memory or disk
        // cache by examining the following properties
        long l1 = com.aspose.imaging.Cache.getAllocatedDiskBytesCount();
        long l2 = com.aspose.imaging.Cache.getAllocatedMemoryBytesCount();
        
        System.out.println("Initial values.");
        System.out.println("Allocated disk space, in bytes: " + l1);
        System.out.println("Allocated memory, in bytes: " + l2);
        System.out.println("--------------------------------------");
        
        // Do some image processing as below
        com.aspose.imaging.imageoptions.GifOptions options = new com.aspose.imaging.imageoptions.GifOptions();
        options.setPalette(new com.aspose.imaging.ColorPalette(
                new com.aspose.imaging.Color[]
                        {
                                com.aspose.imaging.Color.getRed(),
                                com.aspose.imaging.Color.getBlue(),
                                com.aspose.imaging.Color.getBlack(),
                                com.aspose.imaging.Color.getWhite()
                        }));
        options.setSource(new com.aspose.imaging.sources.StreamSource(new com.aspose.imaging.system.io.MemoryStream(), true));
        com.aspose.imaging.RasterImage image = (com.aspose.imaging.RasterImage) com.aspose.imaging.Image.create(options, 100, 100);
        try {
            com.aspose.imaging.Color[] pixels = new com.aspose.imaging.Color[10000];
            for (int i = 0; i < pixels.length; i++) {
                pixels[i] = com.aspose.imaging.Color.getWhite();
            }
        
            System.out.println("Set the white color for 10000 pixels.");
            image.savePixels(image.getBounds(), pixels);
        
            // After executing the code above there will be allocated 40000 bytes in-memory.
            long diskBytes = com.aspose.imaging.Cache.getAllocatedDiskBytesCount();
            long memoryBytes = com.aspose.imaging.Cache.getAllocatedMemoryBytesCount();
            System.out.println("Allocated disk space, in bytes: " + diskBytes);
            System.out.println("Allocated memory, in bytes: " + memoryBytes);
            System.out.println("--------------------------------------");
        } finally {
            System.out.println("Dispose image.");
            image.dispose();
        }
        
        // The allocation properties may be used to check whether all Aspose.Imaging objects were properly disposed.
        // In case you've forgot to call dispose on some object the cache values will be different than 0.
        l1 = com.aspose.imaging.Cache.getAllocatedDiskBytesCount();
        l2 = com.aspose.imaging.Cache.getAllocatedMemoryBytesCount();
        System.out.println("Allocated disk space, in bytes: " + l1);
        System.out.println("Allocated memory, in bytes: " + l2);
        System.out.println("--------------------------------------");
        

      • getAllocatedDiskBytesCount

        public static long getAllocatedDiskBytesCount()

        Gets the allocated disk bytes count.

        Returns:
        The allocated disk bytes count.
        Code example:

        This example demonstrates how to use com.aspose.imaging.Cache


        // By default the cache folder is set to user's local temp directory.
        // You can also specify another cache folder than default like the following:
        // com.aspose.imaging.Cache.setCacheFolder("C:\\Temp");
        
        // Auto mode is flexible and efficient
        com.aspose.imaging.Cache.setCacheType(com.aspose.imaging.CacheType.Auto);
        
        // Default value is 0, which means there is no upper limit
        com.aspose.imaging.Cache.setMaxDiskSpaceForCache(1073741824); // 1 gigabyte
        com.aspose.imaging.Cache.setMaxMemoryForCache(1073741824); // 1 gigabyte
        
        // It is not recommended to change the following property as it may greatly affect the performance
        com.aspose.imaging.Cache.setExactReallocateOnly(false);
        
        // At any time you may check how many bytes currently allocated for memory or disk
        // cache by examining the following properties
        long l1 = com.aspose.imaging.Cache.getAllocatedDiskBytesCount();
        long l2 = com.aspose.imaging.Cache.getAllocatedMemoryBytesCount();
        
        System.out.println("Initial values.");
        System.out.println("Allocated disk space, in bytes: " + l1);
        System.out.println("Allocated memory, in bytes: " + l2);
        System.out.println("--------------------------------------");
        
        // Do some image processing as below
        com.aspose.imaging.imageoptions.GifOptions options = new com.aspose.imaging.imageoptions.GifOptions();
        options.setPalette(new com.aspose.imaging.ColorPalette(
                new com.aspose.imaging.Color[]
                        {
                                com.aspose.imaging.Color.getRed(),
                                com.aspose.imaging.Color.getBlue(),
                                com.aspose.imaging.Color.getBlack(),
                                com.aspose.imaging.Color.getWhite()
                        }));
        options.setSource(new com.aspose.imaging.sources.StreamSource(new com.aspose.imaging.system.io.MemoryStream(), true));
        com.aspose.imaging.RasterImage image = (com.aspose.imaging.RasterImage) com.aspose.imaging.Image.create(options, 100, 100);
        try {
            com.aspose.imaging.Color[] pixels = new com.aspose.imaging.Color[10000];
            for (int i = 0; i < pixels.length; i++) {
                pixels[i] = com.aspose.imaging.Color.getWhite();
            }
        
            System.out.println("Set the white color for 10000 pixels.");
            image.savePixels(image.getBounds(), pixels);
        
            // After executing the code above there will be allocated 40000 bytes in-memory.
            long diskBytes = com.aspose.imaging.Cache.getAllocatedDiskBytesCount();
            long memoryBytes = com.aspose.imaging.Cache.getAllocatedMemoryBytesCount();
            System.out.println("Allocated disk space, in bytes: " + diskBytes);
            System.out.println("Allocated memory, in bytes: " + memoryBytes);
            System.out.println("--------------------------------------");
        } finally {
            System.out.println("Dispose image.");
            image.dispose();
        }
        
        // The allocation properties may be used to check whether all Aspose.Imaging objects were properly disposed.
        // In case you've forgot to call dispose on some object the cache values will be different than 0.
        l1 = com.aspose.imaging.Cache.getAllocatedDiskBytesCount();
        l2 = com.aspose.imaging.Cache.getAllocatedMemoryBytesCount();
        System.out.println("Allocated disk space, in bytes: " + l1);
        System.out.println("Allocated memory, in bytes: " + l2);
        System.out.println("--------------------------------------");
        

      • getMaxMemoryForCache

        public static int getMaxMemoryForCache()

        Gets the maximum available memory for cache in memory. The value specified is megabytes count.

        Returns:
        The maximum memory for cache.

        Value of 0 will consume all available memory and serves as no upper limit.

      • setMaxMemoryForCache

        public static void setMaxMemoryForCache(int value)

        Sets the maximum available memory for cache in memory. The value specified is megabytes count.

        Parameters:
        value - The maximum memory for cache.

        Value of 0 will consume all available memory and serves as no upper limit.

        Code example:

        This example demonstrates how to use com.aspose.imaging.Cache


        // By default the cache folder is set to user's local temp directory.
        // You can also specify another cache folder than default like the following:
        // com.aspose.imaging.Cache.setCacheFolder("C:\\Temp");
        
        // Auto mode is flexible and efficient
        com.aspose.imaging.Cache.setCacheType(com.aspose.imaging.CacheType.Auto);
        
        // Default value is 0, which means there is no upper limit
        com.aspose.imaging.Cache.setMaxDiskSpaceForCache(1073741824); // 1 gigabyte
        com.aspose.imaging.Cache.setMaxMemoryForCache(1073741824); // 1 gigabyte
        
        // It is not recommended to change the following property as it may greatly affect the performance
        com.aspose.imaging.Cache.setExactReallocateOnly(false);
        
        // At any time you may check how many bytes currently allocated for memory or disk
        // cache by examining the following properties
        long l1 = com.aspose.imaging.Cache.getAllocatedDiskBytesCount();
        long l2 = com.aspose.imaging.Cache.getAllocatedMemoryBytesCount();
        
        System.out.println("Initial values.");
        System.out.println("Allocated disk space, in bytes: " + l1);
        System.out.println("Allocated memory, in bytes: " + l2);
        System.out.println("--------------------------------------");
        
        // Do some image processing as below
        com.aspose.imaging.imageoptions.GifOptions options = new com.aspose.imaging.imageoptions.GifOptions();
        options.setPalette(new com.aspose.imaging.ColorPalette(
                new com.aspose.imaging.Color[]
                        {
                                com.aspose.imaging.Color.getRed(),
                                com.aspose.imaging.Color.getBlue(),
                                com.aspose.imaging.Color.getBlack(),
                                com.aspose.imaging.Color.getWhite()
                        }));
        options.setSource(new com.aspose.imaging.sources.StreamSource(new com.aspose.imaging.system.io.MemoryStream(), true));
        com.aspose.imaging.RasterImage image = (com.aspose.imaging.RasterImage) com.aspose.imaging.Image.create(options, 100, 100);
        try {
            com.aspose.imaging.Color[] pixels = new com.aspose.imaging.Color[10000];
            for (int i = 0; i < pixels.length; i++) {
                pixels[i] = com.aspose.imaging.Color.getWhite();
            }
        
            System.out.println("Set the white color for 10000 pixels.");
            image.savePixels(image.getBounds(), pixels);
        
            // After executing the code above there will be allocated 40000 bytes in-memory.
            long diskBytes = com.aspose.imaging.Cache.getAllocatedDiskBytesCount();
            long memoryBytes = com.aspose.imaging.Cache.getAllocatedMemoryBytesCount();
            System.out.println("Allocated disk space, in bytes: " + diskBytes);
            System.out.println("Allocated memory, in bytes: " + memoryBytes);
            System.out.println("--------------------------------------");
        } finally {
            System.out.println("Dispose image.");
            image.dispose();
        }
        
        // The allocation properties may be used to check whether all Aspose.Imaging objects were properly disposed.
        // In case you've forgot to call dispose on some object the cache values will be different than 0.
        l1 = com.aspose.imaging.Cache.getAllocatedDiskBytesCount();
        l2 = com.aspose.imaging.Cache.getAllocatedMemoryBytesCount();
        System.out.println("Allocated disk space, in bytes: " + l1);
        System.out.println("Allocated memory, in bytes: " + l2);
        System.out.println("--------------------------------------");
        

      • getMaxDiskSpaceForCache

        public static int getMaxDiskSpaceForCache()

        Gets the maximum available disk space for cache. The value specified is megabytes count.

        Returns:
        The maximum available disk space for cache.

        Value of 0 will consume all available memory and serves as no upper limit.

      • setMaxDiskSpaceForCache

        public static void setMaxDiskSpaceForCache(int value)

        Sets the maximum available disk space for cache. The value specified is megabytes count.

        Parameters:
        value - The maximum available disk space for cache.

        Value of 0 will consume all available memory and serves as no upper limit.

        Code example:

        This example demonstrates how to use com.aspose.imaging.Cache


        // By default the cache folder is set to user's local temp directory.
        // You can also specify another cache folder than default like the following:
        // com.aspose.imaging.Cache.setCacheFolder("C:\\Temp");
        
        // Auto mode is flexible and efficient
        com.aspose.imaging.Cache.setCacheType(com.aspose.imaging.CacheType.Auto);
        
        // Default value is 0, which means there is no upper limit
        com.aspose.imaging.Cache.setMaxDiskSpaceForCache(1073741824); // 1 gigabyte
        com.aspose.imaging.Cache.setMaxMemoryForCache(1073741824); // 1 gigabyte
        
        // It is not recommended to change the following property as it may greatly affect the performance
        com.aspose.imaging.Cache.setExactReallocateOnly(false);
        
        // At any time you may check how many bytes currently allocated for memory or disk
        // cache by examining the following properties
        long l1 = com.aspose.imaging.Cache.getAllocatedDiskBytesCount();
        long l2 = com.aspose.imaging.Cache.getAllocatedMemoryBytesCount();
        
        System.out.println("Initial values.");
        System.out.println("Allocated disk space, in bytes: " + l1);
        System.out.println("Allocated memory, in bytes: " + l2);
        System.out.println("--------------------------------------");
        
        // Do some image processing as below
        com.aspose.imaging.imageoptions.GifOptions options = new com.aspose.imaging.imageoptions.GifOptions();
        options.setPalette(new com.aspose.imaging.ColorPalette(
                new com.aspose.imaging.Color[]
                        {
                                com.aspose.imaging.Color.getRed(),
                                com.aspose.imaging.Color.getBlue(),
                                com.aspose.imaging.Color.getBlack(),
                                com.aspose.imaging.Color.getWhite()
                        }));
        options.setSource(new com.aspose.imaging.sources.StreamSource(new com.aspose.imaging.system.io.MemoryStream(), true));
        com.aspose.imaging.RasterImage image = (com.aspose.imaging.RasterImage) com.aspose.imaging.Image.create(options, 100, 100);
        try {
            com.aspose.imaging.Color[] pixels = new com.aspose.imaging.Color[10000];
            for (int i = 0; i < pixels.length; i++) {
                pixels[i] = com.aspose.imaging.Color.getWhite();
            }
        
            System.out.println("Set the white color for 10000 pixels.");
            image.savePixels(image.getBounds(), pixels);
        
            // After executing the code above there will be allocated 40000 bytes in-memory.
            long diskBytes = com.aspose.imaging.Cache.getAllocatedDiskBytesCount();
            long memoryBytes = com.aspose.imaging.Cache.getAllocatedMemoryBytesCount();
            System.out.println("Allocated disk space, in bytes: " + diskBytes);
            System.out.println("Allocated memory, in bytes: " + memoryBytes);
            System.out.println("--------------------------------------");
        } finally {
            System.out.println("Dispose image.");
            image.dispose();
        }
        
        // The allocation properties may be used to check whether all Aspose.Imaging objects were properly disposed.
        // In case you've forgot to call dispose on some object the cache values will be different than 0.
        l1 = com.aspose.imaging.Cache.getAllocatedDiskBytesCount();
        l2 = com.aspose.imaging.Cache.getAllocatedMemoryBytesCount();
        System.out.println("Allocated disk space, in bytes: " + l1);
        System.out.println("Allocated memory, in bytes: " + l2);
        System.out.println("--------------------------------------");
        

      • getCacheType

        public static int getCacheType()

        Gets or sets the cache scheme used.

        Returns:
        The cache scheme used.
      • setCacheType

        public static void setCacheType(int value)

        Sets the cache scheme used.

        Parameters:
        value - The cache scheme used.
        Code example:

        This example demonstrates how to use com.aspose.imaging.Cache


        // By default the cache folder is set to user's local temp directory.
        // You can also specify another cache folder than default like the following:
        // com.aspose.imaging.Cache.setCacheFolder("C:\\Temp");
        
        // Auto mode is flexible and efficient
        com.aspose.imaging.Cache.setCacheType(com.aspose.imaging.CacheType.Auto);
        
        // Default value is 0, which means there is no upper limit
        com.aspose.imaging.Cache.setMaxDiskSpaceForCache(1073741824); // 1 gigabyte
        com.aspose.imaging.Cache.setMaxMemoryForCache(1073741824); // 1 gigabyte
        
        // It is not recommended to change the following property as it may greatly affect the performance
        com.aspose.imaging.Cache.setExactReallocateOnly(false);
        
        // At any time you may check how many bytes currently allocated for memory or disk
        // cache by examining the following properties
        long l1 = com.aspose.imaging.Cache.getAllocatedDiskBytesCount();
        long l2 = com.aspose.imaging.Cache.getAllocatedMemoryBytesCount();
        
        System.out.println("Initial values.");
        System.out.println("Allocated disk space, in bytes: " + l1);
        System.out.println("Allocated memory, in bytes: " + l2);
        System.out.println("--------------------------------------");
        
        // Do some image processing as below
        com.aspose.imaging.imageoptions.GifOptions options = new com.aspose.imaging.imageoptions.GifOptions();
        options.setPalette(new com.aspose.imaging.ColorPalette(
                new com.aspose.imaging.Color[]
                        {
                                com.aspose.imaging.Color.getRed(),
                                com.aspose.imaging.Color.getBlue(),
                                com.aspose.imaging.Color.getBlack(),
                                com.aspose.imaging.Color.getWhite()
                        }));
        options.setSource(new com.aspose.imaging.sources.StreamSource(new com.aspose.imaging.system.io.MemoryStream(), true));
        com.aspose.imaging.RasterImage image = (com.aspose.imaging.RasterImage) com.aspose.imaging.Image.create(options, 100, 100);
        try {
            com.aspose.imaging.Color[] pixels = new com.aspose.imaging.Color[10000];
            for (int i = 0; i < pixels.length; i++) {
                pixels[i] = com.aspose.imaging.Color.getWhite();
            }
        
            System.out.println("Set the white color for 10000 pixels.");
            image.savePixels(image.getBounds(), pixels);
        
            // After executing the code above there will be allocated 40000 bytes in-memory.
            long diskBytes = com.aspose.imaging.Cache.getAllocatedDiskBytesCount();
            long memoryBytes = com.aspose.imaging.Cache.getAllocatedMemoryBytesCount();
            System.out.println("Allocated disk space, in bytes: " + diskBytes);
            System.out.println("Allocated memory, in bytes: " + memoryBytes);
            System.out.println("--------------------------------------");
        } finally {
            System.out.println("Dispose image.");
            image.dispose();
        }
        
        // The allocation properties may be used to check whether all Aspose.Imaging objects were properly disposed.
        // In case you've forgot to call dispose on some object the cache values will be different than 0.
        l1 = com.aspose.imaging.Cache.getAllocatedDiskBytesCount();
        l2 = com.aspose.imaging.Cache.getAllocatedMemoryBytesCount();
        System.out.println("Allocated disk space, in bytes: " + l1);
        System.out.println("Allocated memory, in bytes: " + l2);
        System.out.println("--------------------------------------");
        

      • setDefaults

        public static void setDefaults()

        Sets the Cache settings to defaults.