Adding Images to AutoIt GUIs

Tutorial on how to add images to AutoIt GUIs while maintaining aspect ratio.

Edited: 2017-02-10 22:17

In this Tutorial, we will show how to insert images into your GUIs, while also maintaining the aspect ratio of the images you are using.

How to create the actual GUI will not be covered, and it is expected that you at least know the basics of GUI creation. If in doubt, check out the GUI Tutorial.

Loading images into a GUI

.jpg and .gif images can be added to a GUI easily using GUICtrlCreatePic. You need to specify the coordinated in the GUI where you want to insert the image, along with the dimensions of the image, and the path to the image file.

How to maintain the aspect ratio

When you place your image, its useful to know how to maintain the aspect ratio. But to do that you will need to know the dimensions of the image, as we will be using the dimensions to calculate the aspect ratio. The aspect ratio is the width divided by the height of the image.

To get the dimensions directly from the image, rather than having to tyoe them yourself, you can use GDIPlus. The below example shows how to calculate the aspect ratio.