我想将预览框保存为jpeg图像.
我试过写下面的代码:
public void onPreviewFrame(byte[] _data, Camera _camera) { if(settings.isRecording()) { Camera.Parameters params = _camera.getParameters(); params.setPictureFormat(PixelFormat.JPEG); _camera.setParameters(params); String path = "ImageDir" + frameCount; fileRW.setPath(path); fileRW.WriteToFile(_data); frameCount++; } }
但是无法将保存的文件作为jpeg图像打开.有谁知道如何将预览帧保存为jpeg图像?
谢谢
结帐此代码.我希望它有所帮助
camera.setPreviewCallback(new PreviewCallback() { @Override public void onPreviewFrame(byte[] data, Camera camera) { // TODO Auto-generated method stub Camera.Parameters parameters = camera.getParameters(); Size size = parameters.getPreviewSize(); YuvImage image = new YuvImage(data, ImageFormat.NV21, size.width, size.height, null); Rect rectangle = new Rect(); rectangle.bottom = size.height; rectangle.top = 0; rectangle.left = 0; rectangle.right = size.width; ByteArrayOutputStream out2 = new ByteArrayOutputStream(); image.compressToJpeg(rectangle, 100, out2); DataInputStream in = new DataInputStream(); in.write(out2.toByteArray()); } } }); camera.startPreview();