Module: Asposeimagingjava::AddWatermarkToImage

Defined in:
lib/asposeimagingjava/images/addwatermarktoimage.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
24
25
26
27
28
# File 'lib/asposeimagingjava/images/addwatermarktoimage.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 + "aspose.bmp")

    # Create and initialize an instance of Graphics

    graphics = Rjb::import('com.aspose.imaging.Graphics').new(image)

    # Creates an instance of Font

    font = Rjb::import('com.aspose.imaging.Font').new("Times New Roman", 16, Rjb::import('com.aspose.imaging.FontStyle').Bold)

    # Create an instance of SolidBrush and set its various properties.

    brush = Rjb::import('com.aspose.imaging.brushes.SolidBrush').new
    brush.setColor(Rjb::import('com.aspose.imaging.Color').getBlack())
    brush.setOpacity(100)

    # Draw a String using the SolidBrush object and Font, at specific Point.

    graphics.drawString("Aspose.Imaging for Ruby", font, brush, Rjb::import('com.aspose.imaging.PointF').new(image.getWidth()-100, image.getHeight()-100))

    # save the image with changes

    image.save(data_dir + "out.bmp")

    # Display Status.

    puts "Watermark added successfully!"      
end