How to open large size image

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Linh
Posts: 16
Joined: Sun Mar 27, 2011 2:46 pm

How to open large size image

Post by Linh » Sun May 08, 2011 2:16 pm

Hi guys,

I'm developing my first application in LiveCode (Windows platform). I have an Image Object on the current card, and a button to view full size of image. If user click the button, a new card will be opened. I want to put the image (with original size) into the new card. But if size of image is larger than size of new card, I don't know how to display a scroll bar?

In case LiveCode can't display an image in large size, could I use LiveCode call another existing program to open the image (for example Windows Picture and Fax Viewer in Windows)?

Thanks so much!

Cheers,
Linh

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: How to open large size image

Post by Klaus » Sun May 08, 2011 2:30 pm

Hi Linh,

stacks/cards can not have scrollbar in Livecode, but here is the trick:
1. Group your image, yes you can group even a single object!
2. Set the rect of the group to the rect of the card/stack
3. Enable the horzontal and vertical scrollbars for the group
Et voila, a scrollable image :-)

Check the attached stack, one (not too) big image of a christmastree which is grouped.
And check the script of the card to see the "resizestack" script"


Best

Klaus
Attachments
scroll_large_image.rev.zip
(278.28 KiB) Downloaded 648 times

Linh
Posts: 16
Joined: Sun Mar 27, 2011 2:46 pm

Re: How to open large size image

Post by Linh » Sun May 08, 2011 3:06 pm

Thank Klaus. This seems like an excellent solution :) .

I wonder that could we resize the image when the size of card is changed by user?

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: How to open large size image

Post by Klaus » Sun May 08, 2011 3:39 pm

Hi Linh,

my pleasure :D

Sure, resizing is simple!
The "resizestack" message (see the dictionary) comes with 4 parameters:
new width, new height, old width, old height
So you can compute the necessary dimension for the image from this info.
Or use "the rect of this cd" like in my example stack.
Check "the formattedwidth of img X" and "the formattedheigth of img X" to get the actual dimension of the image.

Be sure to keep the aspect ration in your scripts! 8)

I use a function that gives me the new dimensions for a image:

Code: Select all

## tW = Target width
## tH = Target height
## w = total width of image (100%)
## h = total height of image
function make_ratio tW, tH, w, h
  put min (tW/w,tH/h) into tscaleFactor
  return round(w * tscaleFactor) & "," & round(h * tscaleFactor)
end make_ratio
So you can script "on resizestack" like in the attached stack, see card script :)


Best

Klaus
Attachments
zoom_large_image.rev.zip
(278.56 KiB) Downloaded 267 times

Linh
Posts: 16
Joined: Sun Mar 27, 2011 2:46 pm

Re: How to open large size image

Post by Linh » Mon May 09, 2011 2:29 am

Thank Klaus so much!! You're so nice 8)

Post Reply