Previous Page
Next Page

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


Previous Page
Next Page
Converted from CHM to HTML with chm2web Pro 2.85 (unicode)