PDA

View Full Version : off-by-one error w/ mask size


corn flex
12-03-2007, 09:46 PM
I have an mx:Image on a canvas. Behind this image is a mask of the same size, revealing a background that the image in front of it is partially transparent against. The mask should be the same size as the image, obviously. Here's how the code looks in a resize event:

img1.y = (rect.top-2)*2;
img1.x = (rect.left-2)*2;
img1.width = (rect.right-rect.left)*2;
img1.height = (rect.bottom-rect.top)*2;

CnvImg.graphics.clear();
CnvImg.graphics.beginFill(0);
CnvImg.graphics.drawRect(img1.x,img1.y,img1.width, img1.height);
CnvImg.graphics.endFill();

The rectangle drawn on CnvImg is the mask behind image img1. Img1 is actually on a different canvas, of which CnvImg is a child of the same size. (CnvImg is the actual mask, and it is a mask to yet another canvas). But anyway, the whole thing works - the rectangle drawn on CnvImg acts as a mask to reveal a background behind img1 . Here's my problem: After resizing the main canvas, occasionally the mask is one scan line wider than the image in front of it. Its only intermittently it does this, and there's no apparent reason why, because as you can see the rectangle-mask is drawn with the same dimensions as the image. Oh well, thought there was a slight possibility someone might have encountered this before.

corn flex
12-04-2007, 09:37 PM
The rectangle being used to dimension the image had floating point vertices that were rounded differently by drawRect and mx:Image. Found this out about five minutes after posting yesterday.