Page 1 of 1
Image on button distortion
Posted: Fri Apr 29, 2016 8:26 pm
by mrcoollion
Here I am again, asking for help
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
Re: Image on button distortion
Posted: Fri Apr 29, 2016 8:40 pm
by dunbarx
Hi.
I did not open your stack, but have you looked in the dictionary at the "import" command?
Craig Newman
Re: Image on button distortion and how to import image
Posted: Fri Apr 29, 2016 9:16 pm
by mrcoollion
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
Re: Image on button distortion
Posted: Sat Apr 30, 2016 10:00 pm
by dave.kilroy
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
Re: Image on button distortion
Posted: Sun May 01, 2016 8:05 pm
by mrcoollion
Thanks Dave.
Good suggestion.
Regards,
Paul