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