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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/asposeimagingjava/images/addimagesasseparateframesintiff.rb', line 3
def initialize()
data_dir = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) + '/data/'
tiff_expected_format = Rjb::import('com.aspose.imaging.fileformats.tiff.enums.TiffExpectedFormat')
output_settings = Rjb::import('com.aspose.imaging.imageoptions.TiffOptions').new(tiff_expected_format.TiffCcittFax3)
output_settings.setSource(Rjb::import('com.aspose.imaging.sources.FileCreateSource').new(data_dir + "output.tiff", false))
new_width = 500
new_height = 500
tiff_image = Rjb::import('com.aspose.imaging.Image').create(output_settings, new_width, new_height)
index = 0
folder = Rjb::import('java.io.File').new(data_dir + "samples/")
files = folder.listFiles()
files.each do |fileEntry|
image = Rjb::import('com.aspose.imaging.Image').load(fileEntry.getAbsolutePath())
image.resize(new_width, new_height, Rjb::import('com.aspose.imaging.ResizeType').NearestNeighbourResample)
frame = tiff_image.getActiveFrame()
frame.savePixels(frame.getBounds(), image.loadPixels(image.getBounds()))
if index > 0
frame = Rjb::import('com.aspose.imaging.fileformats.tiff.TiffFrame').new(Rjb::import('com.aspose.imaging.imageoptions.TiffOptions').new(output_settings), new_width, new_height)
tiff_image.addFrame(frame)
end
index +=1
end
tiff_image.save()
puts "Added Different Images as Separate Frames in a Multi-Page TIFF"
end
|