dump newbie image questiosn

J. Landman Gay jacque at hyperactivesw.com
Sun Jun 5 20:08:35 EDT 2005


On 6/5/05 4:33 PM, Jon wrote:

> My first learning project was to replicate my Windows image 
> viewer/manipulator in Rev.  That ended with some finality when it turned 
> out that Rev runs so slowly that it cannot possibly process all of the 
> pixels in a real image in the time a reasonable user would sit still.  
> Sigh.

You should be able to do this easily, and I know of several image 
viewers that others have done. It is a trivial task in Revolution, and 
very fast. There are so many image commands and features that you should 
never need to manipulate individual pixel data except in the most 
unusual cases. For a standard image viewer project, never.

This is an excellent first-time project. It should be possible to write 
a simple image viewer in a handful of lines. You can display an image 
from disk in a single line of Transcript. You can set its size in one 
more line. What did you need to do exactly? Maybe we can help you finish 
this.

> 
> I'm now working on a special music/video player, again "porting" it from 
> a Windows implementation.  It's almost finished (in the sense that all 
> of the features seem to work at least once!), but needs a lot of 
> cosmetic work and then lots of testing.   I am displaying guitar 
> tablature in an image along the bottom of the screen.  I want the image 
> to "squeeze" into the given box, but NOT be distorted (a fairly obvious 
> need in my opinion).  So, I need to write (or steal!) the logic that 
> figures out which dimension needs to be adjusted, and then adjust it, 
> and then use the LockLoc (what a strange and unintuitive name!) to let 
> it expand to fill the properly proportioned image container.

LockLoc is short for "lock location" and can also be written 
"locklocation". ;) It overcomes the default behavior of images, which is 
to automatically expand to fit their image contents.

When you put an image from disk into an image object, it will 
automatically resize to fit the image content. If you do not want this 
behavior, you lock the location (that is, you prevent resizing) by 
setting the lockLoc to true. When an image is locked this way, its 
contents will *scale* to fit the image object, rather than the object 
scaling to fit the image content.

> 
> A snippet of code would suffice, although I've written this code enough 
> times that I'm sure I could figure it out again.  I am more annoyed that 
> I even have to than anything else.

I have it somewhere but I'd have to go search for it. It isn't too hard 
though. You just get the width of the available space and the height of 
the available space, then compare them to see which is larger. Use the 
largest one to calculate a ratio. Multiply that ratio times the 
formattedwidth of the image to get the new width; multiply it times the 
formattedheight of the image to get the new height.

If you can't figure it out, post again and I will go look for it. I 
can't remember which project I put it in. ;)

> 
> The Geometry facility is interesting (and novel to me), but I don't know 
> that it will work at all with the kinds of things I want to do.  Because 
> I don't want to distort any images, I will end up altering the shape of 
> the Image object each time an image is loaded.

As per above, if you leave the lockloc of the image object set to false, 
the image will automatically resize to the native dimensions.

>  Eventually, it will be 
> easy to lose track of the original shape/size of the "container" into 
> which I was trying to stuff the images.  There is a concept missing 
> here, I think: we need THREE image sizes (pixel size on disk, size of 
> largest space available on the screen, and actual space used on the 
> screen) rather than the two (first and last, above) that is currently 
> available.  I'm spoiled: all of this was available in a single mode 
> property in my previous IDE.

I'm not sure what you are after exactly, but these can all be retrieved.

Pixel size on disk: formattedwidth and formattedheight of the image.

Space available on screen: you'll have to calculate that, or if it is 
always the same, store it as a constant, a property or a variable, etc.

Actual space used on screen: you can get either the rect of the image, 
or you can get the width and the height of the image. This represents 
the actual current size of the image object.

-- 
Jacqueline Landman Gay         |     jacque at hyperactivesw.com
HyperActive Software           |     http://www.hyperactivesw.com


More information about the use-livecode mailing list