Jump to content

Recommended Posts

  • Moderators
Posted (edited)

Razraal,

Welcome to the AutoIt forums.

From the Help file for GUICtrlCreateButton:

  Quote

A Button control can display an icon or image by using the $BS_ICON or $BS_BITMAP style. Use GUICtrlSetImage() to specify the picture to use.

Expand  

So you need to add the style when creating the button:

$button = GUICtrlCreateButton ("", 10, 10, 40, 40, $BS_BITMAP)
GUICtrlSetImage ($button, "my_image.jpg")

And add the #include <ButtonConstants.au3> line at the top of the script.

M23

Edit 1: Our posts crossed. Is the image file in the same folder as the script?

Edit 2: It seems that it does not work with jpg files - you need to convert it to a BMP. Sorry about that - I have never tried it with a jpg file.

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted
  On 7/25/2016 at 11:23 AM, Melba23 said:

Edit 2: It seems that it does not work with jpg files - you need to convert it to a BMP. Sorry about that - I have never tried it with a jpg file.

Expand  

Hey there @Melba23, thanks for the welcoming!

I've tried with a bmp image, also does not work.

$button = GUICtrlCreateButton ("", 10, 10, 40, 40, $BS_BITMAP)
GUICtrlSetImage ($button, "my_image.bmp")

Converted the original jpg image through GIMP to a bmp image. Same resolution. Same result.

  • Moderators
Posted

Razraal,

I have just tried with a large bmp file and I note that the image is displayed full-size, so only the very centre of the image is shown - which might lead you to think that there is nothing there. Obviously scaling is not done automatically as in the case of a picture control - you learn something new every day.

You will need to rescale the image to the button size - putting a 1000x1000 image on a 40x40 button means you are not going to see much detail anyway.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted
  On 7/25/2016 at 11:44 AM, Melba23 said:

Razraal,

I have just tried with a large bmp file and I note that the image is displayed full-size, so only the very centre of the image is shown - which might lead you to think that there is nothing there. Obviously scaling is not done automatically as in the case of a picture control - you learn something new every day.

You will need to rescale the image to the button size - putting a 1000x1000 image on a 40x40 button means you are not going to see much detail anyway.

M23

Expand  

Thanks for your help mate, I appreciate it!

I've decided to create an image control with GUICtrlCreateImage, instead of a button with an image, since the overal result is almost the same.

  • Moderators
Posted

Razraal,

Delighted I could help.

But when you reply in future, could you please use the "Reply to this topic" button at the top of the thread or the "Reply to this topic" editor at the bottom rather than the "Quote" button - responders know what they wrote and it just pads the thread unnecessarily.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...