本文介绍了应用程序通过空面,拍摄图像时没有surfaceview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个Android应用程序。遇到这样的问题:

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

应用传递NULL表面

app passed NULL surface

在执行下列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();
                }
            }  


主要目标是拍摄照片没有surfaceview,为了存储,并通过电子邮件迅速发送越好。

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

在此先感谢。

推荐答案

我觉得你应该先实现接口SurfaceHolder.Callback,然后添加回调到保持第一,例如,

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(); 

我认为这将是OK !!

I think it will be ok!!

如果您有任何问题,你可以参考一下1.my https://github.com/RyanLiuNtust/Lecture-of-Android/树/ camera_lecture

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

这篇关于应用程序通过空面,拍摄图像时没有surfaceview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 02:53