"Turn" second, the effect of Android image processing nostalgia

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.