0

我使用的代码与 Google 的相机应用程序代码几乎相同,但得到的结果非常奇怪。在我的应用程序和 Google 的相机应用程序中,预览卡住或被奇怪的线条覆盖。预览通常是我在手机自带的相机应用程序中看到的最后一件事。

三星型号是 I9003。相同的代码在三星刚刚停产的 I9000 上运行良好。该代码在 HTC Wildfire 上也能正常工作。

有什么解决办法吗?


刚刚注意到,在我的应用程序中拍照后,相机预览变得正常。Google 相机应用程序中也发生了同样的事情。

4

1 回答 1

0

无法更早地发布答案。不确定这是否是正确的做法,但现在该应用程序在大约 150 台设备上正常运行,我猜这可行。

因此,Android 相机应用在其 onCreate 函数中具有以下代码:

         /*
         * To reduce startup time, we start the preview in another thread.
         * We make sure the preview is started at the end of onCreate.
         */
        Thread startPreviewThread = new Thread(new Runnable() {
            public void run() {
                try {
                    mStartPreviewFail = false;
                    startPreview();
                } catch (CameraHardwareException e) {
                    // In eng build, we throw the exception so that test tool
                    // can detect it and report it
                    if ("eng".equals(Build.TYPE)) {
                        throw new RuntimeException(e);
                    }
                    mStartPreviewFail = true;
                }
            }
        });
        startPreviewThread.start();

由于某种原因,这在 GT-I9003 上不起作用。我注意到的是,拍照后预览会正常进行,因此硬件本身没有任何问题。我试图追溯拍摄照片后发生的事情,然后将其与相机首次初始化的代码进行比较。我从 onCreate 中注释掉了这段代码。相机应用程序的 onResume 如下所示:

if (mSurfaceHolder != null) {
   // If first time initialization is not finished, put it in the
   // message queue.
   if (!mFirstTimeInitialized) {
      mHandler.sendEmptyMessage(FIRST_TIME_INIT);
   } else {
      initializeSecondTime();
   }
}

我将其更改为:

        if (!mFirstTimeInitialized) {
            initializeFirstTime();
        } else {
            initializeSecondTime();
        }

还有一些其他的变化,很快就会把它作为一个单独的应用程序放在 GitHub 上。

于 2011-05-11T22:53:22.993 回答