Home >
Web Front-end >
JS Tutorial >
Examples of implementing six special effects filters in HTML5 Canvas using pure JavaScript_javascript skills
Examples of implementing six special effects filters in HTML5 Canvas using pure JavaScript_javascript skills
WBOY
Release: 2016-05-16 17:30:56
Original
1117 people have browsed it
I tried my hand at it, implemented six simple and common HTML5 Canvas special effects filters, and encapsulated them into a pure JavaScript callable API file gloomyfishfilter.js. The supported special effect filters are: 1. Inverse color 2. Gray tone 3. Blur 4. Embossing 5. Engraving 6 .Mirror
Explanation of filter principle: 1. Inverse color: Get a pixel RGB value r, g, b and the new RGB value is (255-r, 255 -g, 255-b) 2. Gray tone: Get a pixel RGB value r, g, b and the new RGB value is
3. Blur: based on a 5*5 volume Core 4. Relief and engraving: Based on the difference between the RGB value of the previous pixel of the current pixel and the RGB value of the next pixel plus 128 5. Mirror: simulates the object in the mirror the corresponding effect. Miscellaneous preparation 1. How to obtain the Canvas 2d context object