Simple Pictures Example¶
Simple Pictures Example¶
1picture_file_to_load = r"d:\\picture1.jpg"
2picture_file_to_save = r"d:\\picture1saved.jpg"
3
4ad_type_binary = 1
5ad_save_create_over_write = 2
6
7the_dialog = impact.gui.make_dialog("Pictures")
8
9opts1 = impact.gui.create_dialog_picture_options()
10
11# the width and height of the image within the picture control
12opts1.width = 128
13opts1.height = 128
14
15opts1.command_panel_position = ipDialogPictureCommandsPosition.dpcpRightTop
16
17# ensure that any image selected is automatically resized to a specific width and height
18opts1.auto_resize = ipDialogPictureAutoResize.dparScaleToFixed
19opts1.resize_width = 128
20opts1.resize_height = 128
21
22# add a picture field with a label
23pic1 = the_dialog.fields.add_picture(picture_file_to_load, "Picture 1", opts1)
24
25opts2 = impact.gui.create_dialog_picture_options()
26
27# a larger picture control
28opts2.width = 480
29opts2.height = 300
30
31# command panel options
32opts2.command_panel_always_visible = True
33opts2.command_panel_position = ipDialogPictureCommandsPosition.dpcpTop
34
35# hide individual commands
36opts2.hide_command(ipDialogPictureCommand.dpcCopy)
37opts2.hide_command(ipDialogPictureCommand.dpcPaste)
38
39# if no file formats are specified then all raster image formats are allowed
40# otherwise you can specify the individual image formats to allow
41opts2.allow_file_format(ipFileFormat.ffBitmap)
42opts2.allow_file_format(ipFileFormat.ffPNG)
43opts2.allow_file_format(ipFileFormat.ffJPG)
44
45# ensure that any image never exceeds a specific width and height - but any image
46# smaller than this will be left at its original size
47opts2.auto_resize = ipDialogPictureAutoResize.dparShrinkToMaximum
48opts2.resize_width = 1024
49opts2.resize_height = 1024
50
51# load a file into an array (but could also be a db value or image stored somewhere else)
52# stream = CreateObject("ADODB.Stream")
53
54stream.open()
55stream.type = ad_type_binary
56stream.load_from_file(picture_file_to_load)
57
58bytes = stream.read
59
60# add a picture field without a label means the image will be left justified in the dialog
61pic2 = the_dialog.fields.add_picture(bytes, "", opts2)
62
63pic2.hint = "Select a nice picture to show here"
64
65opts3 = impact.gui.create_dialog_picture_options()
66
67opts3.width = 16
68opts3.height = 16
69
70# hide commands panel
71opts3.command_panel_position = ipDialogPictureCommandsPosition.dpcpNone
72
73pic3 = the_dialog.fields.add_picture(picture_file_to_load, "Picture 3", opts3)
74
75# to make a picture control read only set enabled to False
76pic3.enabled = False
77
78# the buttons
79the_dialog.add_button(ipDialogButtonType.dbtClose)
80
81# show the dialog
82the_dialog.show_modal(None)
83
84# retrieve an image and save it to a local file
85# the pic1 options specified that all images would be resized to 128x128
86
87if pic1.picture_has_image:
88
89 # we need the picture BLOB value as a VARIANT array of bytes
90 the_dialog.fields.bytes_as_variant = False
91
92 bytes = pic1.value
93
94 # stream = CreateObject("ADODB.Stream")
95
96 stream.open()
97 stream.type = ad_type_binary
98
99 stream.write(bytes)
100 stream.save_to_file(picture_file_to_save, ad_save_create_over_write)
101
102else:
103 impact.gui.show_message(ipShowMessageType.smtError, "Picture1 has no image assigned", None)