Module: Asposediagramjava::ReplacePictureShape

Defined in:
lib/asposediagramjava/Shapes/replacepictureshape.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
29
30
31
# File 'lib/asposediagramjava/Shapes/replacepictureshape.rb', line 3

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

    # Create instance of Diagram

    diagram = Rjb::import('com.aspose.diagram.Diagram').new(data_dir + "Drawing.vsd")

    # convert image into bytes array       

    fi = Rjb::import('java.io.File').new(data_dir + "star.png")
    file_content = Rjb::import('java.nio.file.Files').readAllBytes(fi.toPath())

    shapes = diagram.getPages().getPage("Flow 1").getShapes()
    
    i = 0
    while i < shapes.getCount()
        shape = shapes.get(i)
        # Filter shapes by type Foreign

        if shape.getType() == Rjb::import('com.aspose.diagram.TypeValue').FOREIGN
            # replace picture shape

            shape.getForeignData().setValue(file_content)
        end

        i +=1
    end

    # Save diagram

    diagram.save(data_dir + "ReplacePictureShape.vdx", Rjb::import('com.aspose.diagram.SaveFileFormat').VDX)

    puts "Replaced picture shape successfully!"
end