问题描述
我现在用的是previewCallback从相机,试图抓住图像。这里是code我使用
I am using the previewCallback from the camera to try and grab images. Here is the code I am using
private Camera.PreviewCallback mPrevCallback = new Camera.PreviewCallback()
{
public void onPreviewFrame( byte[] data, Camera Cam ) {
Log.d("CombineTestActivity", "Preview started");
Log.d("CombineTestActivity", "Data length = "
+ data.length );
currentprev = BitmapFactory.decodeByteArray( data, 0,
data.length );
if( currentprev == null )
Log.d("CombineTestActivity", "currentprev is null" );
Log.d("CombineTestActivity", "Preview Finished" );
}
};
的数据的长度总是OTU相同576000.
the length of the data always comes otu the same as 576000.
此外,我试图改变摄像头的参数,使图像回来为不同的格式。这里是什么样子,当我做到这一点。
Also I have tried changing the parameters of the camera so the image comes back as different formats. Here is what it looks like when I do that.
mCamera = Camera.open();
camParam = mCamera.getParameters();
camParam.setPreviewFormat( ImageFormat.RGB_565 );
mCamera.setParameters( camParam );
mCamera.setPreviewCallback( mPrevCallback );
不过既当我改变preVIEW格式,当我把它作为NV21的默认值,BitmapFactory.de codeByteArray回来为空。我也试图改变preVIEW格式为JPEG类型。我甚至得到了DDMS调试语句,这是我所得到的
However both when I change the preview format and when I leave it as its default of NV21, BitmapFactory.decodeByteArray comes back as null. I have also tried changing the preview format to JPEG type. I even get a debug statement in the ddms, this is what I get
D / Skia的(14391):--- SkImageDe codeR ::厂返回null
"D/skia (14391): --- SkImageDecoder::Factory returned null"
推荐答案
好了,希望这会有所帮助。
Alright, hopefully this will help.
搜罗网上找了快速的解决方案,并找到了完美的东西。
Scoured the internet looking for a fast solution, and found the perfect thing.
这个工作过程的Android 2.1
由于从 off3nsiv3此页面。
// Convert to JPG
Size previewSize = camera.getParameters().getPreviewSize();
YuvImage yuvimage=new YuvImage(data, ImageFormat.NV21, previewSize.width, previewSize.height, null);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
yuvimage.compressToJpeg(new Rect(0, 0, previewSize.width, previewSize.height), 80, baos);
byte[] jdata = baos.toByteArray();
// Convert to Bitmap
Bitmap bmp = BitmapFactory.decodeByteArray(jdata, 0, jdata.length);
只要稍微修改off3nsiv3的code和你设置。比手动解码的FPS依然高得令人难以置信。
Just a little modification to off3nsiv3's code and you're set. The FPS is still incredibly high compared to manual decoding.
有关上述code,80是JPEG质量(0 100,100是最好的)。
For the above code, the 80 is the jpeg quality (0 from 100, 100 being best).
这篇关于BitmapFactory.de codeByteArray()是返回NULL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!