Android相机预览删除绿屏?

时间:2016-10-28 10:20:14

标签: android image-processing camera video-processing

用户将使用前置摄像头,墙上有绿布(彩色背景)

如何访问预览数据并进行更改:删除带有公差的所选颜色?防绿色,耐受65%

@Override
public void onPreviewFrame(final byte[] data, Camera camera) {
    Camera.Parameters parameters = camera.getParameters();
    int width = parameters.getPreviewSize().width;
    int height = parameters.getPreviewSize().height;

    YuvImage yuv = new YuvImage(data, parameters.getPreviewFormat(), width, height, null);

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    yuv.compressToJpeg(new Rect(0, 0, width, height), 50, out);

    byte[] bytes = out.toByteArray();
    final Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);

    MyActivity.this.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            ((ImageView) findViewById(R.id.loopback)).setImageBitmap(bitmap);
        }
    });
}

http://jylee-world.blogspot.ro/2014/12/a-tutorial-of-androidhardwarec

  

我们需要简单的教程。即使在,也没有好的示例代码   http://developer.android.com

1 个答案:

答案 0 :(得分:0)

使用Bitmap.getPixel(int x,int y)获取每个像素的颜色,使用bitmap.setPixel()将颜色更改为您喜欢的颜色

int pixel = bitmap.getPixel(x,y);
int R = Color.red(pixel);
int G = Color.blue(pixel);
int B = Color.green(pixel);

if G == //(range of green values)
    bitmap.setPixel(x, y, color)