I would like to change some of the pixels in the preview to be a bit darker than the rest. Let's say that i would like the top half of the preview to be a bit darker than the bottom half of the preview.
I was trying to use setPreviewCallback like this:
camera.setPreviewCallback(new PreviewCallback() {
// Called for each frame previewed
public void onPreviewFrame(byte[] data, Camera camera) {
Log.d(TAG, "onPreviewFrame called at: " + System.currentTimeMillis());
for (int i = 0; i < data.length; i++){
if(i < data.length/2)
data[i] = manipulate(data[i]);
}
Preview.this.invalidate();
}
});
But it is not working because i am doing something wrong. How can i make it work?
Thanks Eyal
It's not possible to manipulate the preview like that, because you will only get a copy of the buffer into onPreviewFrame.
The easiest thing to do is to overlay another view, which uses transparent canvas to make parts of it darker. The overlay view can implement Camera.PreviewCallback if you need to examine the incoming image to produce the overlay.
In your Activity you do:
setContentView(yourPreviewSurfaceView);
addContentView(yourOverlayView, ...);