manipulating image files

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
dhobbs
Posts: 24
Joined: Tue Dec 15, 2009 6:25 pm

manipulating image files

Post by dhobbs » Mon Feb 08, 2010 4:54 pm

Hello all,
I am new to Revolution, but I have watched the company for years. I have used Hypercard, Prograph, and Python, and written XCMD's for Hypercard way back in the day. I am not a professional programmer.

Currently, I am interested in creating an application for anatomy and physiology students. I can create a drop-down menu of body parts, and I can open cards which contain images and textual definitions of the sub-parts. However, the images are all different resolutions. Currently, I am creating separate cards for each image and size the image appropriately when I create the card. I'm likely to end up with 200 cards this way. I'm wondering if it would be better to have a single card with an image control, and load the image from a file when necessary. The problem is that I don't know how to zoom, or scroll the image so I can center on the region of interest.

Has anyone put a big image in a small window with scroll bars to move the view of the image?

Thanks,

--Doug

Klaus
Posts: 13864
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: manipulating image files

Post by Klaus » Mon Feb 08, 2010 5:19 pm

Hi Doug,

the trick is to do this:
1. create an image object
2. group this single image and enable horizontal and vertical scrollbars for this new group
3. Since "scrolling" windows are not supported by Rev, just add a "resizestack" handler to the card(s) with the group:

Code: Select all

on resizestack
  set the rect of group "the single image" to the rect of this card
  ## Eventually leave room for a tool bar on the top of the window or whatever you need...
end resizestack
Now you can scroll the group after setting the fiulename of the image to an image larger thatn the card vuia script.
I leave the necessary calculations for the scrolling to you ;)
You can query "the formatedheigth" and "the formattedwidth" of the image to have a base for your calculations.

Hope this gets you started!


Best from germany

Klaus

dhobbs
Posts: 24
Joined: Tue Dec 15, 2009 6:25 pm

Re: manipulating image files

Post by dhobbs » Mon Feb 08, 2010 6:50 pm

Thanks!
I haven't tried it yet, but I think I understand what you are suggesting.

In a broader note: am I correct in assuming that a single window that loads image files will be better/faster/more efficient than cards which contain the images directly (up to 200 or so)?
Personally, I like the more flexible solution of one card, but I also want to do what is fastest. I'm not sure I care about how much memory the stack consumes.

Thanks,

--Doug

Klaus
Posts: 13864
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: manipulating image files

Post by Klaus » Mon Feb 08, 2010 7:10 pm

Hi Doug,

glad I could help!

And yes, I also think that the one card approach is the most efficient and fastest one.
Drop a line if you need more help or any assistance!


Best

Klaus

dhobbs
Posts: 24
Joined: Tue Dec 15, 2009 6:25 pm

Re: manipulating image files

Post by dhobbs » Fri Feb 12, 2010 3:02 pm

Ok, so I got the first part of what I wanted to do: I have a button that allows me to choose the graphic file, I have the image in a scrolling group and can scroll images that are larger than the group. I also created buttons for zoom in and out. So now I want to center the image in the scrolling group. The scrolling group is set to "lock size and position", but the image is not. However, I can't center the image unless I unlock the group. It seems the default is for the image top left to be top left of the group. I would much prefer the centers to be aligned - it leads to better zomming behavior. Is there a way to reposition the image in a locked group? Can I programatically unlock the group, reset the image, then relock? Eventually, I would like to click on the image and have it zoom, centered at the mouse location.

Secondly, how do I handle the scrollbars of the group? I can't find a handler for scrolling in the dictionary or documentation. Do I just have to handle a mousedown in a region defined by the scrollbar?

If anyone has suggestions, I'd appreciate it.

--Doug

Klaus
Posts: 13864
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: manipulating image files

Post by Klaus » Sat Feb 13, 2010 2:26 pm

Hi Doug,

1. Center image in group:
Calculate the neccessary scroll values of your group after loading the image and set them:
...
## Do this behind the scenes!
lock screen
set the filename of img "image in group" to XXX

## calculate the values
put the height of grp 1 into tH
put the width of grp 1 into tW
put the formattedheight of grp 1 into fH
put the formattedwidth of grp 1 into fW
put the scrollbarwidth of grp 1 into tS
set the hscroll of grp 1 to round((fh - th + tS)/2)
set the vscroll of grp 1 to round((fW - tW + tS)/2)
unlock screen
...

2. How to mange scrollbars:
set the scroll of grp/field ...
set the hscroll ...

Hope that helps!


Best

Klaus

dhobbs
Posts: 24
Joined: Tue Dec 15, 2009 6:25 pm

Re: manipulating image files

Post by dhobbs » Sat Feb 13, 2010 10:59 pm

Yes. Thanks. I tried searching for "scroll" in the online dictionary, but it didn't point me to vScroll or hScroll.

So, getting closer. When the image is larger than the group (and the scrollbars are active), then zooming behavior works close to what I might expect. The center of the image is the same as the center of the group. However, when the image is smaller than the group, so the scroll thumbs are missing, the default still seems to be to lock the top left of the image with the top left of the group, so my image is displayed in the upper left corner of the group. Commands to the scrollbar don't work (bacause there really isn't one when the image is smaller than the group), nor do commands like "set the loc of image 1 to the loc of group 1". IT's not so bad, but it does look a bit odd when I zoom in from a corner.

One approach I'm thinking about is to test the size of the image, and if it is smaller than some dimensions, then set scrollbar to true and lock the group dimensions. After that, zooming centers with image loc = group loc.

Any other thoughts?

Thanks,

--Doug

dhobbs
Posts: 24
Joined: Tue Dec 15, 2009 6:25 pm

Re: manipulating image files

Post by dhobbs » Sat Feb 13, 2010 11:55 pm

I think I've got it. When I put the image in a group when the scrollbar is false, it centers on the group center. When I do the same thing when the scrollbar is true, it locates the image at the top left of the group. So if I set the scrollbar to false in the beginning, after the image gets to a certain size, I can set the scrollbars to true, then I already know that zooming centers the image in the group.

I'll try it and let you all know.

--Doug

Klaus
Posts: 13864
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: manipulating image files

Post by Klaus » Sun Feb 14, 2010 1:38 pm

Hi Doug,

okie dokie, we trust in you :)


Happy V-day

Klaus

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”