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