Advice on Android TextureView and Bitmap Rendering

1k Views Asked by At

I currently have a piece of code that is very slow. I am trying to get the bitmap from the camera, and edit it, and redraw it on an other surface.

I am using 1 activity so far, MainPreviewActivity extends Activity implements TextureView.SurfaceTextureListener.

I am drawing the camera's stream on a TextureView, (the reason I choose a textureView and not a surfaceView is because I had some issues, getting the RGB values.) Now here is my code below:

public void onSurfaceTextureUpdated(SurfaceTexture surface) {
    // Invoked every time there's a new Camera preview frame

mTextureView.getBitmap(bmp);

for (int x=0; x<imgWidth; x++){
    for (int y=0; y<imgHeight; y++){
        int color = bmp.getPixel(x,y);
        Log.i("Color", Integer.toString(color));
        if(color > 8355711) {
            bmp.setPixel(x, y, Color.argb(255, 255, 255, 255));
        }else{
            bmp.setPixel(x, y, Color.argb(255, 0, 0, 0));
        }
    }
}

    mImageView.setImageBitmap(bmp);
}

Just doing a black & white transformation. As you can see this is very,very slow...

I was wondering how I could make this more efficient?

0

There are 0 best solutions below