bitmap - Android: how to save the first preview frame from SurfaceView -
i wondering if possible save first frame
camera preview, visible on surfaceview
. within activity i've implemented surfaceholder.callback
methods. when call startpreview
on camera object , takepicture
callback executed correctly, need take , save picture more quickly, take first visible frame of preview useful. can do?
suggestion appreciated.
it might seem incredibly simple, save first frame bitmap
.
mcamera.setpreviewcallback(new previewcallback() { public void onpreviewframe(byte[] data, camera camera) { if (image == null) { out = new bytearrayoutputstream(); yuvimage = new yuvimage(data, imageformat.nv21, camera .getparameters().getpreviewsize().width, camera .getparameters().getpreviewsize().height, null); yuvimage.compresstojpeg(new rect(0, 0, camera .getparameters().getpreviewsize().width, camera .getparameters().getpreviewsize().height), 0, out); imagebytes = out.tobytearray(); image = bitmapfactory.decodebytearray(imagebytes, 0, imagebytes.length); } } });
Comments
Post a Comment