我正在开发一个需要在previewcallback()函数中处理每一帧预览的Android应用程序,我的代码是这样的:
Camera c = null;
try {
c = Camera.open(1); // attempt to get a Camera instance
}
catch (Exception e){
// Camera is not available (in use or does not exist)
}
Camera.Size csize = c.getParameters().getPreviewSize();
int mPreviewHeight = csize.height; //
int mPreviewWidth = csize.width;
Camera.Parameters parameters = c.getParameters();
parameters.setPictureSize(800, 800);
// parameters.setPreviewSize(700, 700);
parameters.set("orientation", "portrait");
c.setDisplayOrientation(90);
c.setParameters(parameters);
mPreview = new CameraPreview(this, c);
FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview);
preview.addView(mPreview);
final PreviewCallback mPicture = new PreviewCallback() {
public void onPreviewFrame(byte[] data, Camera camera)
{
try
{
BitmapFactory.Options opts = new BitmapFactory.Options();
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);//,opts);
Log.i("file","Bitmap captured");
}
catch(Exception e)
{
}
}
};
c.setPreviewCallback(mPicture);
但看起来日志“位图捕获”从未显示过,这意味着previewcallback功能没有正常运行,有人可以帮我这个吗?提前谢谢!
答案 0 :(得分:0)
您的CameraPreview课程中包含哪些内容?
我认为你在某个地方呼叫c.startPreview()
?