コード例 #1
0
        /// <summary>
        /// Opens a <seealso cref="com.samsung.android.sdk.camera.SCameraDevice"/>.
        /// </summary>
        private void openCamera()
        {
            try
            {
                if (!mCameraOpenCloseLock.tryAcquire(3000, TimeUnit.MILLISECONDS))
                {
                    showAlertDialog("Time out waiting to lock camera opening.", true);
                }

                mSCameraManager = mSCamera.SCameraManager;

                SCameraCharacteristics characteristics        = mSCameraManager.getCameraCharacteristics(mCameraId);
                StreamConfigurationMap streamConfigurationMap = characteristics.get(SCameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);

                // Acquires supported preview size list that supports YUV420_888.
                // Input Surface from panorama processor will have a format of ImageFormat.YUV420_888
                mPreviewSize = streamConfigurationMap.getOutputSizes(ImageFormat.YUV_420_888)[0];

                foreach (Size option in streamConfigurationMap.getOutputSizes(ImageFormat.YUV_420_888))
                {
                    // preview size must be supported by panorama processor
                    if (!contains(mProcessor.Parameters.get(SCameraPanoramaProcessor.STREAM_SIZE_LIST), option))
                    {
                        continue;
                    }

                    int areaCurrent = Math.Abs((mPreviewSize.Width * mPreviewSize.Height) - (MAX_PREVIEW_WIDTH * MAX_PREVIEW_HEIGHT));
                    int areaNext    = Math.Abs((option.Width * option.Height) - (MAX_PREVIEW_WIDTH * MAX_PREVIEW_HEIGHT));

                    if (areaCurrent > areaNext)
                    {
                        mPreviewSize = option;
                    }
                }

                int orientation = Resources.Configuration.orientation;
                if (Configuration.ORIENTATION_LANDSCAPE == orientation)
                {
                    mTextureView.setAspectRatio(mPreviewSize.Width, mPreviewSize.Height);
                }
                else
                {
                    mTextureView.setAspectRatio(mPreviewSize.Height, mPreviewSize.Width);
                }

                initProcessor();

                mSCameraManager.openCamera(mCameraId, new StateCallbackAnonymousInnerClassHelper(this), mBackgroundHandler);
            }
            catch (CameraAccessException e)
            {
                showAlertDialog("Cannot open the camera.", true);
                Log.e(TAG, "Cannot open the camera.", e);
            }
            catch (InterruptedException e)
            {
                throw new Exception("Interrupted while trying to lock camera opening.", e);
            }
        }
コード例 #2
0
        private void openCamera()
        {
            lock (this)
            {
                try
                {
                    if (!mCameraOpenCloseLock.tryAcquire(3000, TimeUnit.MILLISECONDS))
                    {
                        showAlertDialog("Time out waiting to lock camera opening.", true);
                    }



                    // acquires camera characteristics
                    mCharacteristics = mSCameraManager.getCameraCharacteristics(mSCameraManager.CameraIdList[0]);

                    StreamConfigurationMap streamConfigurationMap = mCharacteristics.get(SCameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);

                    // Acquires supported preview size list that supports SurfaceTexture
                    mPreviewSize = streamConfigurationMap.getOutputSizes(typeof(SurfaceTexture))[0];
                    foreach (Size option in streamConfigurationMap.getOutputSizes(typeof(SurfaceTexture)))
                    {
                        // Find maximum preview size that is not larger than MAX_PREVIEW_WIDTH/MAX_PREVIEW_HEIGHT
                        int areaCurrent = Math.Abs((mPreviewSize.Width * mPreviewSize.Height) - (MAX_PREVIEW_WIDTH * MAX_PREVIEW_HEIGHT));
                        int areaNext    = Math.Abs((option.Width * option.Height) - (MAX_PREVIEW_WIDTH * MAX_PREVIEW_HEIGHT));

                        if (areaCurrent > areaNext)
                        {
                            mPreviewSize = option;
                        }
                    }

                    // Acquires supported input size for YUV_420_888 format.
                    Size yuvSize = streamConfigurationMap.getInputSizes(ImageFormat.YUV_420_888)[0];

                    // Configures an ImageReader
                    mYUVReader  = ImageReader.newInstance(yuvSize.Width, yuvSize.Height, ImageFormat.YUV_420_888, 2);
                    mJpegReader = ImageReader.newInstance(mYUVReader.Width, mYUVReader.Height, ImageFormat.JPEG, 2);

                    mYUVReader.setOnImageAvailableListener(mYUVImageListener, mReaderHandler);
                    mJpegReader.setOnImageAvailableListener(mJpegImageListener, mReaderHandler);

                    // Set the aspect ratio to TextureView
                    int orientation = Resources.Configuration.orientation;
                    if (orientation == Configuration.ORIENTATION_LANDSCAPE)
                    {
                        mTextureView.setAspectRatio(mPreviewSize.Width, mPreviewSize.Height);
                    }
                    else
                    {
                        mTextureView.setAspectRatio(mPreviewSize.Height, mPreviewSize.Width);
                    }

                    // Opening the camera device here
                    mSCameraManager.openCamera(mCameraId, new StateCallbackAnonymousInnerClassHelper(this), mBackgroundHandler);
                }
                catch (CameraAccessException e)
                {
                    showAlertDialog("Cannot open the camera.", true);
                    Log.e(TAG, "Cannot open the camera.", e);
                }
                catch (InterruptedException e)
                {
                    throw new Exception("Interrupted while trying to lock camera opening.", e);
                }
            }
        }