简体   繁体   中英

How to apply photo effects/filters on Run time in android Camera?

Please suggest me How to apply photo effects/filters on Run time in android Camera? with out using JNI , OpenGl and open CV. I need to apply effects only through Java code.

Step 1. Convert frame from NV21 to format supported by some image processing library. You can read how to do it here or here

Step 2. Use image processing library to perform filtering. For example you can use ImageJ . You can read about how to use ImageJ here or here or here .

Check out the Image Processing to apply various effects on Image. It provides various effects to be applied on Image after capturing.

Suppose i want to apply contrast effect on image then i will use the below method:

 public static Bitmap createContrast(Bitmap src, double value) { // image size int width = src.getWidth(); int height = src.getHeight(); // create output bitmap Bitmap bmOut = Bitmap.createBitmap(width, height, src.getConfig()); // color information int A, R, G, B; int pixel; // get contrast value double contrast = Math.pow((100 + value) / 100, 2); // scan through all pixels for(int x = 0; x < width; ++x) { for(int y = 0; y < height; ++y) { // get pixel color pixel = src.getPixel(x, y); A = Color.alpha(pixel); // apply filter contrast for every channel R, G, B R = Color.red(pixel); R = (int)(((((R / 255.0) - 0.5) * contrast) + 0.5) * 255.0); if(R < 0) { R = 0; } else if(R > 255) { R = 255; } G = Color.red(pixel); G = (int)(((((G / 255.0) - 0.5) * contrast) + 0.5) * 255.0); if(G < 0) { G = 0; } else if(G > 255) { G = 255; } B = Color.red(pixel); B = (int)(((((B / 255.0) - 0.5) * contrast) + 0.5) * 255.0); if(B < 0) { B = 0; } else if(B > 255) { B = 255; } // set new pixel color to output bitmap bmOut.setPixel(x, y, Color.argb(A, R, G, B)); } } // return final image return bmOut; } 

Use above method as:

  BitMap bmp =BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length); //Here you can define your image and convert it into Bitmap. bmp = createContrast(bm,75); mImageView.setImageBitmap(bmp); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM