简体   繁体   English

如何在Android Camera的运行时上应用照片效果/滤镜?

[英]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? 请建议我如何在Android Camera的运行时上应用照片效果/滤镜? with out using JNI , OpenGl and open CV. 无需使用JNI,OpenGl和Open CV。 I need to apply effects only through Java code. 我只需要通过Java代码应用效果。

Step 1. Convert frame from NV21 to format supported by some image processing library. 步骤1.将帧从NV21转换为某些图像处理库支持的格式。 You can read how to do it here or here 您可以在这里这里阅读操作方法

Step 2. Use image processing library to perform filtering. 步骤2.使用图像处理库执行过滤。 For example you can use ImageJ . 例如,您可以使用ImageJ You can read about how to use ImageJ here or here or here . 您可以在此处此处此处阅读有关如何使用ImageJ的信息

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); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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