Two hours ago I was a big friend of AppleScript Studio, now I’m furious with its bugs.
I develop something like a slide-show, there is a main window with thumbnail-pictures.
If you click on it, you see the image beside in a bigger view. I tried so many things,
to make images clickable: It does’t work, although this feature is documentated.
I tried to put image cells into tables, to make images clickable. It doesn’t work.
Now I took image buttons as thumbnails. I can click them, but they can not fit to
my pictures right.
I have 640x480 pictures, if I load them as images and assign them to the (small) buttons,
the buttons doesn’t fit the images to own size; some buttons do, some buttons
only show a part of the whole pic, without resizing the pic
something very obscute happens to the images: if I want to show a thumbnail image in the big view, I take them back from the buttons. some images now get a very low resolution, some not.
This is nowere documentated! Does anyone have an idea, how to solve my problem, either to make image views clickable or to handle button images ???
Thanx, thanx, thanx for your answers !!!
Helge, Germany
I looked around, and I can’t find a method of adjusting the scaling of images in buttons. Unless you want to make individual thumbs for every image, using buttons alone is not your answer. There is another post here which is kind of relavent, but deals with using text fields rather than image views…although the concept is nearly identical. I created a test app that does what I think your trying to do, and here’s what I came up with…
Create a set/grid of image views that will be your “thumbnails”. Set their border to ‘invisible’, alignment to ‘center’, and scaling to ‘proportionally’. I also set the ‘editable’ and ‘enabled’ values to false (unchecked) to avoid any unneccessary or unexpected conflicts later.
Create a button for each of the image views, and fit them to cover each respective image view exactly. I used a square button, with ‘border’= false, ‘transparent’=true, obviously ‘enabled’=true. You also might want to highlight each button and select “Bring to Front” in the “Layout” menu in Interface Builder so they are definitely displayed OVER the image views underneath them.
In your script the first thing is to set up properties which store your current thumbnails. That way the app will always know which images are being used and what the path to each is.
property thumbImage1 : missing value
property thumbImage2 : missing value
-- etc...
Next, set up the code which sets the images in the thumb image views. You might want to do this in an ‘awake from nib’ or ‘will open’ for the window to set the defaults, and then in a ‘clicked’ for when you go to the next/previous set. Also, you’ll probably want to get more creative than hard-coding the image names (“picture1.jpg”, etc…). I added in some UNTESTED code to give you an idea of what your releasing code might look like (see below).
on some event theObject
-- Get the paths of all the old images
set oldThumbImage1 to image of image view "thumb1" of window "mainWindow"
set oldThumbImage2 to image of image view "thumb2" of window "mainWindow"
set oldThumbImage3 to image of image view "thumb3" of window "mainWindow"
set pathToImages to "whatever:the:path:to:your:images:is"
set thumbImage1 to load image ((pathToImages & "picture1.jpg") as string)
set thumbImage2 to load image ((pathToImages & "picture2.jpg") as string)
set thumbImage3 to load image ((pathToImages & "picture3.jpg") as string)
set image of image view "thumb1" of window "mainWindow" to thumbImage1
set image of image view "thumb2" of window "mainWindow" to thumbImage2
set image of image view "thumb3" of window "mainWindow" to thumbImage3
-- Try to delete all of the old images
try
delete oldThumbImage1
delete oldThumbImage2
delete oldThumbImage3
end try
end some event
Receive the clicks of the buttons in your clicked handler…
on clicked theObject
if name of theObject is "thumbButton1" then
set image of image view "pictureWindow" of window "mainWindow" to thumbImage1
else if name of theObject is "thumbButton2" then
set image of image view "pictureWindow" of window "mainWindow" to thumbImage2
-- etc...
end if
end clicked
You’ll definitely want to release the old images after you change them to a new set. I posted some code in This Thread dealing with paths and other image issues that may help you. The last post of mine in the that thread has a working version of the ‘delete oldImage’ command which you could modify and use to release your images when you’re done with them, so they don’t hog memory.
Regarding your resolution… If the image is too big to fit in the image view, apple’s “amazing” scaling algorithm will reduce it’s size to fit the image view (which can get a bit grainy, especially around the edges). If it’s too small to fit, depending on the settings of the image view’s properties it may be enlarged to fit (which can be even worse for your image resolution). You can either suck it up and live with the resolution, or consider making the main image view resizable (or huge) if possible, so the user can determine their own threshold of acceptable resolution.