/// <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; mMediaRecorder = new MediaRecorder(); // 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); } }
/// <summary> /// Closes a camera and release resources. /// </summary> private void closeCamera() { try { mCameraOpenCloseLock.acquire(); if (null != mSCameraSession) { mSCameraSession.close(); mSCameraSession = null; } if (null != mSCameraDevice) { mSCameraDevice.close(); mSCameraDevice = null; } mSCameraManager = null; mSCamera = null; } catch (InterruptedException e) { Log.e(TAG, "Interrupted while trying to lock camera closing.", e); } finally { mCameraOpenCloseLock.release(); } }
protected internal override void onResume() { base.onResume(); // initialize SCamera mSCamera = new SCamera(); try { mSCamera.initialize(this); } catch (SsdkUnsupportedException) { showAlertDialog("Fail to initialize SCamera.", true); return; } if (!checkRequiredFeatures()) { return; } mSCameraManager = mSCamera.SCameraManager; mTextureView = (AutoFitTextureView)findViewById(R.id.texture); // Set SurfaceTextureListener that handle life cycle of TextureView mTextureView.SurfaceTextureListener = new SurfaceTextureListenerAnonymousInnerClassHelper(this); findViewById(R.id.picture).OnClickListener = new OnClickListenerAnonymousInnerClassHelper(this); startBackgroundThread(); openCamera(); }
private void IosStart() { Instance = this; SCameraManager.CreateCamera(SCameraType.EASYAR); GameObject Gyro = new GameObject(); Gyro.name = "GyroController"; Gyro.AddComponent <MySkyGyroController>(); Gyro.transform.SetParent(GameObject.Find("Manager").gameObject.transform); Gyro.transform.localPosition = Vector3.zero; SCameraManager.currentCamera.gameObject.transform.SetParent(Gyro.transform); m_BlurOptimized = SCameraManager.currentCamera.camera.gameObject.GetComponent <BlurOptimized>(); m_SUILoading = SUILoading.CreateLoading(); Start3D = PlayerPrefs.GetInt("3DStart"); Start3D++; PlayerPrefs.SetInt("3DStart", Start3D); // PlayerPrefs.SetInt("GUIDE3D", 1); MsgBase.MsgAdd <string>("OnOpenScene", OnOpenScene); MsgBase.MsgAdd <string, Callback>("RemoveScene2", RemoveScene2); MsgBase.MsgAdd <string>("RemoveScene", RemoveScene1); MsgBase.MsgAdd("RemoveTutorial", RemoveTutorial); MsgBase.MsgAdd <string>("HideScene", HideScene); MsgBase.MsgAdd <bool, float>("ShowBlur", ShowBlur); OnOpenScene("UI"); if (PlayerPrefs.GetInt("GUIDE3D") == 3) { OnOpenScene("PhotoScene"); } }
/// <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); } }
private void createUI() { ViewGroup torchButtons = (ViewGroup) findViewById(R.id.torch_buttons_layout); torchButtons.removeAllViews(); mCameraIdViewMap = new Dictionary<>(); mSCameraManager = mSCamera.SCameraManager; int numberOfCameraWithFlash = 0; try { foreach (string id in mSCameraManager.CameraIdList) { ViewGroup torchItem = (ViewGroup)LayoutInflater.inflate(R.layout.torch_item, null); torchButtons.addView(torchItem); ((TextView)torchItem.findViewById(R.id.cameraId_textView)).Text = id; ToggleButton toggleButton = (ToggleButton)torchItem.findViewById(R.id.toggleButton); toggleButton.Tag = id; if (mSCameraManager.getCameraCharacteristics(id).get(SCameraCharacteristics.FLASH_INFO_AVAILABLE)) { numberOfCameraWithFlash++; toggleButton.OnClickListener = new OnClickListenerAnonymousInnerClassHelper(this); } else { toggleButton.Checked = false; toggleButton.Enabled = false; } mCameraIdViewMap[id] = toggleButton; } mSCameraManager.registerTorchCallback(new TorchCallbackAnonymousInnerClassHelper(this), null); } catch (CameraAccessException e) { Console.WriteLine(e.ToString()); Console.Write(e.StackTrace); } ((TextView)findViewById(R.id.totalNumber_textView)).Text = "Number of camera device with flash unit = " + numberOfCameraWithFlash; }
private void createUI() { ViewGroup torchButtons = (ViewGroup)findViewById(R.id.torch_buttons_layout); torchButtons.removeAllViews(); mCameraIdViewMap = new Dictionary <>(); mSCameraManager = mSCamera.SCameraManager; int numberOfCameraWithFlash = 0; try { foreach (string id in mSCameraManager.CameraIdList) { ViewGroup torchItem = (ViewGroup)LayoutInflater.inflate(R.layout.torch_item, null); torchButtons.addView(torchItem); ((TextView)torchItem.findViewById(R.id.cameraId_textView)).Text = id; ToggleButton toggleButton = (ToggleButton)torchItem.findViewById(R.id.toggleButton); toggleButton.Tag = id; if (mSCameraManager.getCameraCharacteristics(id).get(SCameraCharacteristics.FLASH_INFO_AVAILABLE)) { numberOfCameraWithFlash++; toggleButton.OnClickListener = new OnClickListenerAnonymousInnerClassHelper(this); } else { toggleButton.Checked = false; toggleButton.Enabled = false; } mCameraIdViewMap[id] = toggleButton; } mSCameraManager.registerTorchCallback(new TorchCallbackAnonymousInnerClassHelper(this), null); } catch (CameraAccessException e) { Console.WriteLine(e.ToString()); Console.Write(e.StackTrace); } ((TextView)findViewById(R.id.totalNumber_textView)).Text = "Number of camera device with flash unit = " + numberOfCameraWithFlash; }
// Use this for initialization void Start() { #if UNITY_IOS Messenger.AddListener("U2N_N_StartAppCamera", delegate(){ //TODO 开启场景和AR相机 IosStart(); }); #endif #if UNITY_ANDROID Instance = this; SCameraManager.CreateCamera(SCameraType.EASYAR); GameObject Gyro = new GameObject(); Gyro.name = "GyroController"; Gyro.AddComponent <MySkyGyroController>(); Gyro.transform.SetParent(GameObject.Find("Manager").gameObject.transform); Gyro.transform.localPosition = Vector3.zero; SCameraManager.currentCamera.gameObject.transform.SetParent(Gyro.transform); m_BlurOptimized = SCameraManager.currentCamera.camera.gameObject.GetComponent <BlurOptimized>(); m_SUILoading = SUILoading.CreateLoading(); Start3D = PlayerPrefs.GetInt("3DStart"); Start3D++; PlayerPrefs.SetInt("3DStart", Start3D); // PlayerPrefs.SetInt("GUIDE3D", 1); MsgBase.MsgAdd <string>("OnOpenScene", OnOpenScene); MsgBase.MsgAdd <string, Callback>("RemoveScene2", RemoveScene2); MsgBase.MsgAdd <string>("RemoveScene", RemoveScene1); MsgBase.MsgAdd("RemoveTutorial", RemoveTutorial); MsgBase.MsgAdd <string>("HideScene", HideScene); MsgBase.MsgAdd <bool, float>("ShowBlur", ShowBlur); OnOpenScene("UI"); // if (PlayerPrefs.GetInt("GUIDE3D") == 3) { // OnOpenScene("PhotoScene"); } #endif }
/// <summary> /// Closes a camera and release resources. /// </summary> private void closeCamera() { lock (this) { try { mCameraOpenCloseLock.acquire(); if (mSCameraSession != null) { mSCameraSession.close(); mSCameraSession = null; } if (mSCameraDevice != null) { mSCameraDevice.close(); mSCameraDevice = null; } mSCameraManager = null; } catch (InterruptedException e) { Log.e(TAG, "Interrupted while trying to lock camera closing.", e); } finally { mCameraOpenCloseLock.release(); } } }
protected internal override void onResume() { base.onResume(); // initialize SCamera mSCamera = new SCamera(); try { mSCamera.initialize(this); } catch (SsdkUnsupportedException) { showAlertDialog("Fail to initialize SCamera.", true); return; } if (!checkRequiredFeatures()) { return; } mSCameraManager = mSCamera.SCameraManager; mTextureView = (AutoFitTextureView) findViewById(R.id.texture); // Set SurfaceTextureListener that handle life cycle of TextureView mTextureView.SurfaceTextureListener = new SurfaceTextureListenerAnonymousInnerClassHelper(this); findViewById(R.id.picture).OnClickListener = new OnClickListenerAnonymousInnerClassHelper(this); startBackgroundThread(); openCamera(); }
/// <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; // acquires camera characteristics SCameraCharacteristics characteristics = mSCameraManager.getCameraCharacteristics(mCameraId); StreamConfigurationMap streamConfigurationMap = characteristics.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 size for JPEG format Size[] jpegSizeList = null; jpegSizeList = streamConfigurationMap.getOutputSizes(ImageFormat.JPEG); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && 0 == jpegSizeList.Length) { // If device has 'SCameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES_BURST_CAPTURE' getOutputSizes can return zero size list // for a format value in getOutputFormats. jpegSizeList = streamConfigurationMap.getHighResolutionOutputSizes(ImageFormat.JPEG); } Size jpegSize = jpegSizeList[0]; // Configures an ImageReader mImageReader = ImageReader.newInstance(jpegSize.Width, jpegSize.Height, ImageFormat.JPEG, mProcessor.Parameters.get(SCameraDepthOfFieldProcessor.MULTI_INPUT_COUNT_RANGE).Upper); mImageReader.setOnImageAvailableListener(mImageCallback, mBackgroundHandler); // 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); } // Initialize depth of field processor initProcessor(); // 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); } }
/// <summary> /// Opens a <seealso cref="com.samsung.android.sdk.camera.SCameraDevice"/>. /// </summary> private void openCamera(int facing) { lock (this) { try { if (!mCameraOpenCloseLock.tryAcquire(3000, TimeUnit.MILLISECONDS)) { showAlertDialog("Time out waiting to lock camera opening.", true); } mSCameraManager = mSCamera.SCameraManager; mCameraId = null; // Find camera device that facing to given facing parameter. foreach (string id in mSCamera.SCameraManager.CameraIdList) { SCameraCharacteristics cameraCharacteristics = mSCamera.SCameraManager.getCameraCharacteristics(id); if (cameraCharacteristics.get(SCameraCharacteristics.LENS_FACING) == facing) { mCameraId = id; break; } } if (mCameraId == null) { showAlertDialog("No camera exist with given facing: " + facing, true); return; } // acquires camera characteristics mCharacteristics = mSCamera.SCameraManager.getCameraCharacteristics(mCameraId); 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 size for JPEG format Size[] jpegSizeList = null; jpegSizeList = streamConfigurationMap.getOutputSizes(ImageFormat.JPEG); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && 0 == jpegSizeList.Length) { // If device has 'SCameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES_BURST_CAPTURE' getOutputSizes can return zero size list // for a format value in getOutputFormats. jpegSizeList = streamConfigurationMap.getHighResolutionOutputSizes(ImageFormat.JPEG); } Size jpegSize = jpegSizeList[0]; // Configures an ImageReader mJpegReader = ImageReader.newInstance(jpegSize.Width, jpegSize.Height, ImageFormat.JPEG, 1); mJpegReader.setOnImageAvailableListener(mImageCallback, mImageSavingHandler); if (contains(mCharacteristics.get(SCameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES), SCameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES_RAW)) { Size[] rawSizeList = streamConfigurationMap.getOutputSizes(ImageFormat.RAW_SENSOR); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && 0 == rawSizeList.Length) { rawSizeList = streamConfigurationMap.getHighResolutionOutputSizes(ImageFormat.RAW_SENSOR); } Size rawSize = rawSizeList[0]; mRawReader = ImageReader.newInstance(rawSize.Width, rawSize.Height, ImageFormat.RAW_SENSOR, 1); mRawReader.setOnImageAvailableListener(mImageCallback, mImageSavingHandler); mImageFormatList = Arrays.asList(ImageFormat.JPEG, ImageFormat.RAW_SENSOR); } else { if (mRawReader != null) { mRawReader.close(); mRawReader = null; } mImageFormatList = Arrays.asList(ImageFormat.JPEG); } mImageFormat = ImageFormat.JPEG; // Set the aspect ratio to TextureView int orientation = Resources.Configuration.orientation; if (orientation == Configuration.ORIENTATION_LANDSCAPE) { mTextureView.setAspectRatio(mPreviewSize.Width, mPreviewSize.Height); mFaceRectView.setAspectRatio(mPreviewSize.Width, mPreviewSize.Height); } else { mTextureView.setAspectRatio(mPreviewSize.Height, mPreviewSize.Width); mFaceRectView.setAspectRatio(mPreviewSize.Height, mPreviewSize.Width); } // calculate transform matrix for face rect view configureFaceRectTransform(); // 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); } } }