Skip to content Skip to sidebar Skip to footer

Getting Image Data Continuously From Camera, Surfaceview Or Surfaceholder

So I have this camera preview set up with Camera, SurfaceView and SurfaceHolder. I have also an ImageView where I will be putting a modified version of the camera image and I want

Solution 1:

I went for option number 2 and finally made it work.

used this callback, forgot the @Override before

private Camera.PreviewCallback  previewCallback= newCamera.PreviewCallback()
{   
    @OverridepublicvoidonPreviewFrame(byte[] data,Camera cam)
    {
            Camera.SizepreviewSize= cam.getParameters().getPreviewSize();
            YuvImageyuvImage=newYuvImage(data, ImageFormat.NV21,previewSize.width,previewSize.height, null);
            ByteArrayOutputStreambaos=newByteArrayOutputStream();
            yuvImage.compressToJpeg(newRect(0,0,previewSize.width,previewSize.height),80,baos);
            byte[] jdata = baos.toByteArray();
            Bitmapbitmap= BitmapFactory.decodeByteArray(jdata,0,jdata.length);    
    }
};

And initiating it using setPreviewCallback rather than setPreviewCallbackWithBuffer

SurfaceHolder.Callback surfaceCallback=newSurfaceHolder.Callback() 
{   
    publicvoidsurfaceCreated(SurfaceHolder holder) {

        camera.setPreviewCallback(previewCallback);
    }
}

Post a Comment for "Getting Image Data Continuously From Camera, Surfaceview Or Surfaceholder"