Puzzling image drift

PEChumbley at aol.com PEChumbley at aol.com
Sat Jan 26 19:04:01 EST 2002


To illustrate the situation in one dimension, if a line is 99 pixels wide, 
its centerpoint is at 50 with 49 pixels before and 49 pixels after the 
centerpoint.  But if the line is 100 pixels wide, the centerpoint is actually 
at 50 1/2.  Since you can't center the line on a half pixel, the line would 
be shifted slightly right or left from true center (depending whether you 
round up or truncate the number) so the image is now offset.  If you now make 
the line 99 pixels wide again it will stay centered in the same place but 
switching it back to 100 pixels wide again will shift it once again.  If the 
half-way points are rounded up (ie. 50 1/2 --> 51), the effect would be that 
a line would drift to the left or an image to the upper left.  To correct for 
that, simply read the location of the first image into a variable (oldLoc) 
and include a line saying:

set the loc of image myImage to oldLoc

after setting the filename.  Be aware that you may see the image "jump" 
slightly.  If that is unacceptable, make the image invisible, set the 
fileName to the new name, set the loc to the oldLoc , and then make it 
visible.  In my application I use two images.  While viewing one, I set the 
file name of the invisible one and reposition it and then hide one and show 
the other.

Hope this helps.

Philip Chumbley



More information about the metacard mailing list