Android(onPreviewFrame):将NV21数据保存为JPEG文件

Android(onPreviewFrame):将NV21数据保存为JPEG文件,android,camera,jpeg,Android,Camera,Jpeg,我为onPreviewFrame()回调编写了以下代码。它现在可以将数据保存为JPEG文件,我可以在浏览器中查看,但不能在Windows Picture Viewer中查看。我的代码有问题吗 YuvImage im = new YuvImage(data, ImageFormat.NV21, size.width, size.height, null); Rect r = new Rect(0,0,size.width,size.height);

我为onPreviewFrame()回调编写了以下代码。它现在可以将数据保存为JPEG文件,我可以在浏览器中查看,但不能在Windows Picture Viewer中查看。我的代码有问题吗

YuvImage im = new YuvImage(data, ImageFormat.NV21, size.width,
                        size.height, null);
Rect r = new Rect(0,0,size.width,size.height);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
im.compressToJpeg(r, parameters.getJpegQuality(), baos);

try{
   FileOutputStream output = new FileOutputStream(String.format(
        "/sdcard/%s_%d.jpg", strPrevCBType, System.currentTimeMillis()));
   output.write(baos.toByteArray());
   output.flush();
   output.close();
}catch(FileNotFoundException e){
}catch(IOException e){
}
谢谢,

artsylar

我的代码现在正在运行。我不知道昨天发生了什么,但唯一的区别是我现在使用adb命令来提取文件,而昨天我使用的是Eclipse文件资源管理器

但为了以防万一,有更好的方法来编写此代码,请让我知道