启动preVIEW功能是缓慢的,任何变通? [英] The startPreview function is slow, Any work around?

查看:260
本文介绍了启动preVIEW功能是缓慢的,任何变通?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:

我在做Android上,需要从相机的快速响应,同时拍摄图像的应用程序,我注意到来自应用程序的缓慢行为,测量时间后,我发现功能开始preVIEW()是负责的问题。

I'm making an application on android which requires a fast response from the camera while shooting images, I noticed a slow behavior from the application, after measuring the time I noticed that function startPreview() is the responsible of the problem.

code preVIEW:

这是code(相关问题)的必要组成部分。

This is the necessary part of the code (related to the problem).

previewGoogle类(自定义preVIEW):
上的应用surfaceChanged叫的开始,我给自己定了一些相机参数,然后叫开始preVIEW

public class PreviewGoogle extends ViewGroup implements SurfaceHolder.Callback {
    private final String TAG = "myapp1";
    Camera mCamera;

    public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
        try
        {
            // Now that the size is known, set up the camera parameters and begin
            // the preview.
            Camera.Parameters parameters = mCamera.getParameters();

            parameters.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
            parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_INFINITY);
            parameters.setWhiteBalance(Camera.Parameters.WHITE_BALANCE_AUTO);
            parameters.setSceneMode(Camera.Parameters.SCENE_MODE_AUTO);
            parameters.setJpegQuality(100);
            parameters.setPictureSize(Globals.CAMERA_WIDTH, Globals.CAMERA_HEIGHT);

            requestLayout();
            mCamera.setParameters(parameters);

            long before = System.currentTimeMillis();
            mCamera.startPreview();
            long after = System.currentTimeMillis();

            Log.d(TAG, "PreviewGoogle, surfaceChanged: startPreview took " + (after - before) + " ms");
        }
        catch (Exception e) {
            Log.d(TAG, "PreviewGoogle, surfaceChanged: " + e.getMessage());
        }
    }
}

PhotoShootActivity类: 在这个班我呼吁rawImageCallback开始preVIEW因为我使用的jpegCallback的BitmapFactory(没有必要的事情)

public class PhotoShootActivity extends Activity
{
    private static final String TAG = "myapp1";
    PreviewGoogle preview;

    // Handles data for raw picture
    PictureCallback rawCallback = new PictureCallback()
    {
        public void onPictureTaken(byte[] data, Camera camera)
        {
            try
            {
                long before = System.currentTimeMillis();
                preview.getCamera().startPreview();
                long after = System.currentTimeMillis();

                Log.d(PhotoShootActivity.TAG, "PhotoShootActivity, rawCallback: preview started in " + (after - before) + " ms");
            }
            catch(Exception e)
            {
                Log.e(TAG, "PhotoShootActivity, rawCallback: " + e.getMessage());
            }
        }
    };
}

计时器数字是这样的:

The Timer Numbers were like this:

09-09 10:58:42.336: DEBUG/myapp1(21958): PhotoShootActivity, onCreate
**09-09 10:58:44.396: DEBUG/myapp1(21958): PreviewGoogle, surfaceChanged: startPreview took 1457 ms**
09-09 10:58:48.438: DEBUG/myapp1(21958): PhotoShootActivity, buttonCapture: Picture taken in 65ms
09-09 10:58:48.496: DEBUG/myapp1(21958): PhotoShootActivity, shutterCallback: Empty
**09-09 10:58:49.790: DEBUG/myapp1(21958): PhotoShootActivity, rawCallback: preview started in 662 ms**

首先开始的preVIEW拿了〜1500毫秒,第二把662毫秒!

我在寻找的问题是不是一个完整的code(只是小费我:)),我以为我可以缺少在preVIEW东西,我想过这个使用线程情况下,但我不熟悉Android的SDK,但(我开始使用Android编程5天前)

The question I'm looking for is not a full code (just tip me :)), I've thought that I could missing something in the preview, and I thought about using threads in this case but I'm not familiar with android-sdk yet (I started with android programing 4 days ago)

问候...

推荐答案

从Android文档:

From the android docs:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

启动preVIEW()

启动捕获并绘制preVIEW帧到屏幕上。 preVIEW才会真正开始,直到表面与集previewDisplay(SurfaceHolder) 组提供previewTexture(表面纹理)

Starts capturing and drawing preview frames to the screen. Preview will not actually start until a surface is supplied with setPreviewDisplay(SurfaceHolder) or setPreviewTexture(SurfaceTexture).

如果集previewCallback(相机。previewCallback) setOneShot previewCallback(相机。previewCallback) 集previewCallbackWithBuffer(相机。previewCallback)被称为在previewFrame(字节[],摄像机)时preVIEW数据变得可用将被调用。

If setPreviewCallback(Camera.PreviewCallback), setOneShotPreviewCallback(Camera.PreviewCallback), or setPreviewCallbackWithBuffer(Camera.PreviewCallback) were called, onPreviewFrame(byte[], Camera) will be called when preview data becomes available.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

因此​​,在您的评论你说你决定使用上previewFrame(字节[],摄像机),你可以在文档中看到,它说,它当preVIEW数据变得可用,whihc需要一些时间才会被调用。尝试通过提供摄像头,纹理或preVIEW显示添加第一个选项。

So in your comment you said you decided to use onPreviewFrame(byte[], Camera), as you can see in the docs, it says it is only called when the preview data becomes available, whihc takes some time. Try adding the first option by providing the camera with a texture or a preview display.

也就是说,在你的 surfaceChanged(SurfaceHolder架,INT格式,诠释W,INT高)方法:

Ie, in your surfaceChanged(SurfaceHolder holder, int format, int w, int h) method:

mCamera.setPreviewDisplay(holder);

看看是否有差别。

See if that makes a difference.

这篇关于启动preVIEW功能是缓慢的,任何变通?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆