简体   繁体   English

Camera.Preview 回调不生成相机帧

[英]Camera.Preview Callback not generating Camera Frames

I have created a customized System Service, and i want my service to capture Camera frames in the background without Preview.我创建了一个自定义的系统服务,我希望我的服务在没有预览的情况下在后台捕获相机帧。 I have followed the steps in developer.android website and implemented the following code, but it is not generating any frames.我已经按照 developer.android 网站中的步骤执行了以下代码,但它没有生成任何帧。 Here is the code:这是代码:

 public void startCapture() {

//Start The camera
int openCamera = 0;//default camera to be opened
mCamera = Camera.open(openCamera);
Camera.Parameters p = mCamera.getParameters();
setPreviewSize(p.getPreviewSize());//method to get Camera size
mCamera.getParameters().setPreviewFpsRange(1, 2);
try{
    Camera.PreviewCallback mPreviewCallback = new Camera.PreviewCallback()
    { 

    @Override

    public void onPreviewFrame(byte[] data, Camera camera) {

    //  public void cameraPreview(byte[] data, Camera camera) {

    // TODO Auto-generated method stub

    decodeYUV420SP(rgb, data, width, height);//method for processing the image  

    bitmap.setPixels(rgb, 0, width, 0, 0, width, height);  

    String newFolder = "/Pictures";

    String extStorageDirectory = Environment.getExternalStorageDirectory().toString();

    File myNewFolder = new File(extStorageDirectory + newFolder);

    if (!myNewFolder.exists())

        myNewFolder.mkdir();            



    File file = new File(path, "/Pictures/Frame-"+count+".jpg");

    boolean fileCreated = file.createNewFile();

    FileOutputStream out = new FileOutputStream(file);

    bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);

    out.flush();

    out.close();
    };

}catch (Exception e) 
 {

       e.printStackTrace();

 }
}
mCamera.setPreviewCallback(mPreviewCallback);
mCamera.startPreview();
}

I wanted the frames to be captured and Stored in the SD Card in the Mentioned path.but i am not getting it done.我希望在提到的路径中捕获帧并将其存储在 SD 卡中。但我没有完成。 what am i doing wrong here.我在这里做错了什么。 Need some Help!需要一些帮助!

Thanks to the Replier in Advance.提前感谢回复者。

I had a similar problem.我有一个类似的问题。 You need to synchronize against the 'holder' object of you view, lock the canvas, process the frame and then unlock the canvas again.您需要与您查看的“持有人”object 同步,锁定 canvas,处理框架,然后再次解锁 canvas。 The problem I think is that the preview data is returned in the callback and drawn to the screen in tandem (synchronisation keyword allows you to trap it).我认为的问题是预览数据在回调中返回并串联绘制到屏幕上(同步关键字允许您捕获它)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM