[squeak-dev] Re: Trying to combine two images

Andreas Raab andreas.raab at gmx.de
Sat Aug 7 04:16:26 UTC 2010


On 8/6/2010 6:22 PM, Schwab,Wilhelm K wrote:
> Are there any good examples of using a mask to highlight portions of an image?  I have an onion-skin effect in mind, but could live with almost anything that is easy to see and does not obliterate the underlying image.  The goal is to paint a mask that will select irregular regions of an image.
>
> If I have a black and white mask, I can use #eraseShape: and #reverse to get two separate images, and I appear to be able to make the masked portion of one of them transpaent and can (not terribly well) highlight the masked portion of the other.  Things quickly sprial down hill when I try to combine the two pieces.  Any pointers would be appreciatiated.
>
> Bill

Try this for starters:

	maskForm := Form dotOfSize: 400.
	(BitBlt toForm: Display)
		sourceForm: maskForm;
		destX: 100; destY: 100;
		colorMap: (WordArray with: 16rC0FFFFFF with: 0);
		combinationRule: Form blend;
		copyBits.

This will fill the exterior of the dot (to fill the interior just flip 
the order of colors in the color map) directly on the target. If you 
don't want (or can't) use simple alpha, then use mask with a bitOr: rule 
to clear the uncovered areas. Here is the same example with a 
screen-door effect instead of alpha-blending:

	maskForm := Form dotOfSize: 400.
	alphaForm := Form extent: maskForm extent depth: 8.
	"Fill alphaForm with the desired pattern"
	(alphaForm getCanvas)
		fillRectangle: alphaForm boundingBox
		color: (Color white alpha: 0.5).
	"Now mask out the area we don't want"
	(BitBlt toForm: alphaForm)
		sourceForm: maskForm;
		colorMap: (WordArray with: 16rFFFFFFFF with: 0);
		combinationRule: Form and;
		copyBits.
	alphaForm displayOn: Display at: 100 at 100 rule: Form paint.

And of course, if your mask is alpha to begin with, this can be heavily 
simplified.

Cheers,
   - Andreas



More information about the Squeak-dev mailing list