Recipe 10.9. Sharpening


Problem

You want to apply a sharpening effect to a display object.

Solution

Use a sharpening matrix and apply it with a convolution filter.

Discussion

You can sharpen an object by using a matrix very similar to the structure of the matrix that detects edges. The only difference is that with an edge detection matrix the center value is negative surrounded by positive values; the sharpen matrix, instead uses a positive center value surrounded by negative values. The following example sharpens a display object:

sampleSprite.filter = [new ConvolutionFilter(3, 3, [0, -1, 0, -1, 5, -1, 0, -1, 0])];

You can apply a less dramatic sharpen effect by increasing the center value and using a divisor:

sampleSprite.filter = [new ConvolutionFilter(3, 3, [0, -1, 0, -1, 10, -1, 0, -1, 0], 5)];

You can apply a more dramatic sharpen effect by decreasing the center value and either increasing the surrounding values or using a divisor:

sampleSprite.filter = [new ConvolutionFilter(3, 3, [0, -1, 0, -1, 1, -1, 0, -1, 0], -3)];

See Also

Recipe 10.6




ActionScript 3. 0 Cookbook
ActionScript 3.0 Cookbook: Solutions for Flash Platform and Flex Application Developers
ISBN: 0596526954
EAN: 2147483647
Year: 2007
Pages: 351

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net