Android Camera Real-Time Filter (4), androidcamera
Implementation of custom algorithms based on PS special effects on Android platform Created with Rapha rjl 2.1.2 Start Image Bitmap Get pixel getPixels The PS algorithm modifies the pixel Color. red/green/blue. Filter Image End
In the ARGB color space, four values, A (Transparency), R (Red), G (Green), and B (Blue), are used to describe A pixel, for an image with a width of w and h, there are a total of w x h pixels. You can use an array object int [] pixels to represent the corresponding image. pixels = {p1, p2, p3 ...}. When each pixel is represented by ARGB, this image can be described using a [w * h, 4] matrix:
pixels = { pa1,pr1,pg1,pb1, pa2,pr2,pg2,pb2, pa3,pr3,pg3,pb3, ……}
The android platform provides the Bitmap. getPixels method for obtaining pixels. What I need to do is to traverse the pixels of the image and calculate each pixel. After the calculated pixels are processed by the Color. red/green/blue method, fill in the pixels back to Bitmap to obtain the image after the filter. This method is more flexible than ColorMatrix and can meet the Implementation Effect of PS special effects.
1. Simple Reversed Filter Implementation
Take out the pixels of the image, and then subtract 255 from each pixel. The result is a reversed image.
The algorithm is as follows:
/*** @ Author neil */public class AntiColorFilter implements ImageFilterInterface {private ImageData image = null; // image Information class public AntiColorFilter (Bitmap bmp) {image = new ImageData (bmp);} public ImageData imageProcess () {int width = image. getWidth (); int height = image. getHeight (); int R, G, B, pixel; for (int y = 0; y
2. Implementation of oil painting Filter
By checking the information, we can see that the algorithm of the oil painting filter is to replace the color of the current vertex with any color within a certain range around the current vertex. The most commonly used is random replacement of adjacent vertices"
The algorithm is as follows:
Public ImageData imageProcess () {int width = image. getWidth (); int height = image. getHeight (); int R, G, B, pixel, xx = 0, yy = 0; for (int y = 0; y
3. Frozen Filter Implementation
The ice filter algorithm is to deepen the pixel color, each pixel is represented by the RGB three primary colors, (255,255,255, 0) is pure black, and () is pure white, therefore, the RGB color of no pixels is reduced, and the color will deepen.
Int width = image. getWidth (); int height = image. getHeight (); int R, G, B, pixel; for (int y = 0; y