Image on button distortion

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
mrcoollion
Posts: 738
Joined: Thu Sep 11, 2014 1:49 pm

Image on button distortion

Post by mrcoollion » Fri Apr 29, 2016 8:26 pm

Here I am again, asking for help :oops:

I am trying to get an image out of a file on a button.
This all works well but the image is distorted.
When I import the same image in a stack there is no problem.

I attached a sample stack and included the jpg image file to show you what I mean.

The goal is to get an image from a database and use it in a button without to have it be imported into a stack.
If it is not possible without importing it into a stack as a control I would like to get a sample script on how to import an image as a control from a file into a stack (could not find the right code).

Kind regards,

Paul
Attachments
IconButtonDistortionExample.zip
Icon on button distortion example
(17.56 KiB) Downloaded 211 times

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10354
Joined: Wed May 06, 2009 2:28 pm

Re: Image on button distortion

Post by dunbarx » Fri Apr 29, 2016 8:40 pm

Hi.

I did not open your stack, but have you looked in the dictionary at the "import" command?

Craig Newman

mrcoollion
Posts: 738
Joined: Thu Sep 11, 2014 1:49 pm

Re: Image on button distortion and how to import image

Post by mrcoollion » Fri Apr 29, 2016 9:16 pm

Hi Craig,

Yes I did and it does work. The "import" command also works for jpg, gif, bmp and png image files.
Placed a sample stack that includes a button with the "import" command for others to see the difference and how to do it.
I hoped that there was a way without having to generate an image with the importstatement.

Regards,

Paul
Attachments
IconButtonDistortion2.zip
Icon buttons distortion and the way to solcve this with import.
(45.67 KiB) Downloaded 236 times

dave.kilroy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 858
Joined: Wed Jun 24, 2009 1:17 pm
Contact:

Re: Image on button distortion

Post by dave.kilroy » Sat Apr 30, 2016 10:00 pm

Hi Paul, try the following in a button script - it assumes you have an image "imgHolder" and a button "btnShowImage".

Code: Select all

on mouseup
    answer file "choose an image file"
    if it is not empty then  set the filename of img "imgHolder" to it
    --
    put the width of img "imgHolder" / the height of img 1 into tRatio
    --
    if the height of btn "btnShowImage" > the width of btn "btnShowImage" then
        set the width of img "imgHolder" to the width of btn "btnShowImage"
        set the height of img "imgHolder" to (the width of img "imgHolder" / tRatio)
    else
        set the width of img "imgHolder" to the height of btn "btnShowImage"
        set the height of img "imgHolder" to (width of img "imgHolder" / tRatio)
    end if
    --
    set the icon of btn "btnShowImage" to the id of img "imgHolder"
end mouseup
It works by finding the smallest dimension of the button and setting the image size to that proportionally, it then sets the icon of the button to the image. This results in the image appearing in the button at the size of the smallest dimension of the button and undistorted. During all this the image can remain hidden with only the button visible
"...this is not the code you are looking for..."

mrcoollion
Posts: 738
Joined: Thu Sep 11, 2014 1:49 pm

Re: Image on button distortion

Post by mrcoollion » Sun May 01, 2016 8:05 pm

Thanks Dave.

Good suggestion.

Regards,

Paul

Post Reply