• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps problems with the camera

D

Deleted User

Guest
Hi everyone!

I'm developing an application that uses the camera.

The idea is to get frames continuosly and modify this photos (for example convert to grey scale) and show the result in real time.

I'm using the method onPreviewFrame(byte[] data, Camera camera) to get the image and convert it.

The question is, once the conversion is already done, how I refresh the preview in real time to obtain the modified image?

I try with this code, but it's not working:

Camera.PreviewCallback previewCall = new Camera.PreviewCallback() {
public void onPreviewFrame(byte[] data, Camera camera) {
// Do something with the preview image.
if (isPreviewRunning) {
camera.stopPreview();
isPreviewRunning = false;
}

Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length, opt);

mRgbImage = mRgbImageAndroid.toRgbImage(bitmap);

mRgbImage.greyScale();

Canvas c = surfaceHolder.lockCanvas();

c.drawBitmap(mRgbImage.getData(), 0, mRgbImage.getWidth(), 0, 0, mRgbImage.getWidth(), mRgbImage.getHeight(), false, null);

surfaceHolder.unlockCanvasAndPost(c);

try {
camera.setPreviewDisplay(surfaceHolder);
} catch (IOException e) {
Log.d("3", "Error al actualizar la imagen");
camera.release();
}

camera.startPreview();
isPreviewRunning = true;
}
};

Thanks ;)
 
If you want to change the view to black and white you can do that from the Camera.Parameters settings. There are a number of different filters that you can use, and you dont have to worry about the nightmare of converting the image data back into an image, you can just use the camera preview.
 
Upvote 0
Thanks, but this code is only an example... i want to do more things than convert the image to grayscale.

My intent is to work with the image information to do anything with it, and for that I should be able to modify it and then preview it.
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones