Module: Asposeimagingjava::SpecifyBitdepthForPngImage

Defined in:
lib/asposeimagingjava/images/specifybitdepthforpngimage.rb

Instance Method Summary collapse

Instance Method Details

#initializeObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/asposeimagingjava/images/specifybitdepthforpngimage.rb', line 3

def initialize()
    data_dir = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) + '/data/'

    # Load an existing image (of type bmp) in an instance of Image class

    image = Rjb::import('com.aspose.imaging.Image').load(data_dir + "sample.png")

    # Create an instance of PngOptions

    options = Rjb::import('com.aspose.imaging.imageoptions.PngOptions').new
    
    # Set the desired ColorType

    options.setColorType(Rjb::import('com.aspose.imaging.fileformats.png.PngColorType').Grayscale)
                  
    # Set the BitDepth according to the specified ColorType

    options.setBitDepth(1)

    # Save the result on disc

    image.save(data_dir + "specify_bitdepth.png", options)

    # Display Status.

    puts "Specified bit depth for PNG image successfully!"
end