app passed NULL surface, while taking a picture without a surfaceview

我与影子孤独终老i 提交于 2019-12-10 10:45:25

问题


I'm writing an android app. I encounter the following problem:

app passed NULL surface

while executing the following code:



    public void takePictureNoPreview(Context context){
            try {
                myCamera = Camera.open(0);
            } catch (Exception e) {
                e.printStackTrace();
                console.append("Failed to connect to camera\n");
            }
            if(myCamera!=null){
                SurfaceView dummy=new SurfaceView(context);
                try {
                    myCamera.setPreviewDisplay(dummy.getHolder());
                    myCamera.startPreview(); 
                    myCamera.takePicture(null, null, getJpegCallback());
                } 
                catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }    
                finally
                {
                    myCamera.stopPreview();
                    myCamera.release();
                }
            }  


The main goal is to take a picture without the surfaceview, in order to store it and send via email as quickly as possible.

Thanks in advance.


回答1:


I think you should implement the interface SurfaceHolder.Callback first, and then add callback to the holder first, e.g.

mHolder.addCallback(callback)
myCamera.setPreviewDisplay(mHolder);
myCamera.startPreview(); 

I think it will be ok!!

If you have any problems, you can refer to 1.my https://github.com/RyanLiuNtust/Lecture-of-Android/tree/camera_lecture




回答2:


You can't do it. There are some privacy issues with the camera. I have seen this answer on one of the boards here before but I don't have time to look that answer up again. You can't do it, because if your app takes a picture of something they should be able to know what it is of.



来源:https://stackoverflow.com/questions/16945524/app-passed-null-surface-while-taking-a-picture-without-a-surfaceview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!