Imagedata row order

J. Landman Gay jacque at hyperactivesw.com
Sun Jul 23 14:59:19 EDT 2006


Trevor DeVore wrote:

 > I need to experiment with this for a project I'm working on so I worked
 > in this handler yesterday.  You just provide the long id of a src image
 > (the image to tile) and the destination image (the image to perform the
 > tiling in).  I've only tested this on OS X with Rev 2.7.x but it is
 > working well here.

Only I don't have a source image. I'm making one. :)

 > By the way, it seems that in 2.7.x that backgroundPatterns can be any
 > size.  There is a note in the What's New.txt file that says this is the
 > case for graphics but I tried setting the backgroundPattern of a field
 > to an image that was 405 x 29 and it appeared correctly on OS X.  The
 > pattern evens scrolls with the field which is cool.  If
 > backgroundPatterns behave like this on Windows as well then perhaps
 > there is no need to roll your own tiling handler.

Looks like you are making big images. I'm making teeny ones. Maybe 
someone is interested, so here is what I needed, and what I ended up 
doing, and how I got there. (If nobody's interested, skip the rest.)

Goal: The user arranges objects on screen. These are large objects that 
fit into an 8x8 grid, each having a "color" that is really a gradient. 
When they are done, they have a unique 8x8 pattern. I need to capture 
the pattern, represent it in a 32-pixel square icon that repeats the 
pattern 4 times across and 4 times down. In other words, I need to 
reduce a very large screen image made of gradients into a clear icon 
using only 64 pixels per patttern (1024 pixels total.)

First thing I tried: take a snapshot of the area. Reduce it to 32 pixels 
square by resizing the image and then setting its imagedata in order to 
reduce the amount of data stored in the image object. Result: fuzzy, 
indistinct icon containing only one pattern instead of 8 repeating 
patterns. The gradients didn't reduce well, of course. I thought about 
reducing the image to 8 pixels square and duplicating it, but this first 
attempt proved that anything smaller would be nothing but a blob.

Second thing I tried: Storing the user pattern as a series of different 
characters to represent each object's main color. This gave me 8 chars 
per line and 8 lines. Then I created an off-screen group of buttons in a 
grid 8x8, and set the colors of the buttons to match the user's pattern. 
This gave a flat color for each button and removed the problem with the 
gradients. I took a snapshot of that, reduced it to 32 pixels square, 
and set the imagedata of a  new image. Result: very clear icon of the 
right size, but still only has one pattern instead of 8. I considered 
adding more objects to my offscreen grid to make a repeating pattern, 
but decided to try the next method instead.

Third (successful) method: Ditch the offscreen grid, but continue to 
translate the user pattern into a series of characters and lines in a 
variable. Multiply each line of characters by 4 so I have enough 
characters (pixels) to fill my image (this is where I went wrong before; 
I didn't multiply enough times and didn't have enough pixels.) Then I 
translated the character set to colors in binary and put those into a 
variable in the right order. Finally I set the imagedata of a newly 
created image to the imagedata I'd just created. Bingo, it works. Teeny 
little repeating pattern, each one 8 pixels square, repeated 16 times 
inside a little icon.

There it is, just in case anyone needs to do this. Which I doubt. :)

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



More information about the Use-livecode mailing list