Image effects Processing series will introduce the image of the pixel point of effect processing, these materials focus on the principle. This means that as long as you know that these algorithms can make the same effects, whether c++,vb,c#,java or not. The following is an introduction to the image nostalgic effect algorithm. The algorithm is as follows:
The above formula means that the RGB value of each pixel is separated first, then the RGB value is recalculated and then the RGB value of the current point, respectively, according to the above three calculation.
Below is a look at the film:
Original Picture:
After processing:
Code:
/*** Nostalgic effect (one times faster than previous optimizations) *@paramBMP *@return */ PrivateBitmap oldremeber (Bitmap bmp) {//Speed Test LongStart =System.currenttimemillis (); intwidth =bmp.getwidth (); intHeight =bmp.getheight (); Bitmap Bitmap=bitmap.createbitmap (width, height, Bitmap.Config.RGB_565); intPixcolor = 0; intPIXR = 0; intPIXG = 0; intPIXB = 0; intNEWR = 0; intNEWG = 0; intNewb = 0; int[] pixels =New int[Width *height]; Bmp.getpixels (Pixels,0, Width, 0, 0, width, height); for(inti = 0; i < height; i++) { for(intk = 0; K < width; k++) {Pixcolor= Pixels[width * i +K]; PIXR=color.red (Pixcolor); Pixg=Color.green (Pixcolor); PIXB=Color.Blue (Pixcolor); NEWR= (int) (0.393 * PIXR + 0.769 * pixg + 0.189 *PIXB); NEWG= (int) (0.349 * PIXR + 0.686 * pixg + 0.168 *PIXB); Newb= (int) (0.272 * PIXR + 0.534 * pixg + 0.131 *PIXB); intNewcolor = Color.argb (255, NEWR > 255? 255:newr, NEWG > 255? 255:NEWG, Newb > 255? 255: NEWB); Pixels[width* i + K] =Newcolor; }} bitmap.setpixels (pixels,0, Width, 0, 0, width, height); LongEnd =System.currenttimemillis (); LOG.D ("May", "used time=" + (End-start)); returnbitmap; }
The above code is optimized, that is, the use of the getpixels () and setpixels (). A simple test of their own, faster than the original GetPixel () and setpixel () speed faster than a second.