Save layer as image¶
Save layer as image¶
1# This example shows how to save all the layers of a drawing as images
2
3ot = impact.gui.output_toolbox
4
5ot.clear()
6
7# create an IImageFormatParams object, then set the properties
8image_format = impact.creator.image_format_params()
9image_format.width = 256 # pixels
10image_format.height = 256 # pixels
11image_format.resolution = 72
12image_format.compression_factor = 50
13image_format.colour_depth = ipImageColourFormat.ic24Bit
14image_format.compression = ipCompressionFormat.cfDefault
15
16# create an ISaveImageParams object and define the properties
17# (the border size is in your current distance impact.units)
18image_params = impact.creator.save_image_params()
19image_params.image_format_params = image_format
20image_params.file_format = ipFileFormat.ffPNG
21image_params.left_border_size = 20
22image_params.right_border_size = 20
23image_params.top_border_size = 20
24image_params.bottom_border_size = 20
25
26counter = 1
27
28start = timer
29
30for layer in active_drawing.layers:
31 image_params.file_path = r"d:\Images\Layer" + str(counter) + ".png"
32
33 if layer.save_layer_as_image(image_params):
34 ot.add("Image " + image_params.file_path + " for layer '" + layer.full_name + "' saved successfully")
35 else:
36 ot.add("Failed to Save Image " + image_params.file_path + " for layer '" + layer.full_name + "'")
37
38 counter = counter + 1
39
40ms = int((timer - start) * 1000)
41
42ot.add("Generated images in " + str(ms) + "ms")
43