private void updateCameraParametersPreference() { // Set picture size. String pictureSize = mPreferences.getString(KEY_PICTURE_SIZE, null); if (pictureSize == null) { initialCameraPictureSize(this, mParameters); } else { List<Size> supported = mParameters.getSupportedPictureSizes(); setCameraPictureSize(pictureSize, supported, mParameters); } // Set the preview frame aspect ratio according to the picture size. Size size = mParameters.getPictureSize(); PreviewFrameLayout frameLayout = (PreviewFrameLayout) findViewById(R.id.frame_layout); frameLayout.setAspectRatio((double) size.width / size.height); // Set a preview size that is closest to the viewfinder height and has // the right aspect ratio. List<Size> sizes = mParameters.getSupportedPreviewSizes(); Size optimalSize = getOptimalPreviewSize(sizes, (double) size.width / size.height); if (optimalSize != null) { mParameters.setPreviewSize(optimalSize.width, optimalSize.height); } mParameters.setJpegQuality(85); updateFlashModeParameter(); }
private void initialCameraPictureSize(Context context, Parameters parameters) { List<Size> supported = parameters.getSupportedPictureSizes(); if (supported == null) return; for (String candidate : context.getResources().getStringArray(R.array.pref_camera_picturesize_entryvalues)) { if (setCameraPictureSize(candidate, supported, parameters)) { SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit(); editor.putString(KEY_PICTURE_SIZE, candidate); editor.commit(); return; } } }
/** * Listener for on screen clicks. Workaround for bug in 2.3.X: we stop the preview and start a new * one against a null surface Then take the picture. */ public void onClick(View v) { if ((mCamera != null) && (!mCapturing)) { mCapturing = true; mCamera.stopPreview(); mCamera.setPreviewCallback(null); Parameters params = mCamera.getParameters(); Size defaultSize = params.getSupportedPictureSizes().get(0); int[] size = PanoCamera.getCameraSize(mContext, defaultSize.width, defaultSize.height); Log.d("OpenCV_Base", "Size is " + size[0] + "x" + size[1]); params.setPictureSize(size[0], size[1]); mCamera.setParameters(params); try { mCamera.setPreviewDisplay(null); mCamera.startPreview(); mCamera.takePicture(null, null, jpegCallback); } catch (IOException e) { // Camera is unavailable, don't take a picture // TODO: alert user } } }
// TODO >>>> Set Picture Size From Screen public void setPictureSizeOfScreenAndPreviewsize() { Parameters params = cam.getParameters(); List<Camera.Size> sizes = params.getSupportedPictureSizes(); boolean sizesupportofscreen = false; for (int i = 0; i < sizes.size(); i++) { PrintLog.print( activity.getApplicationContext(), sizes.get(i).width + "|" + sizes.get(i).height + " : : " + Deviceinfo.getDeviceScreenSize(activity)[0] + "|" + Deviceinfo.getDeviceScreenSize(activity)[1]); if ((sizes.get(i).width == Deviceinfo.getDeviceScreenSize(activity)[0] && sizes.get(i).height == Deviceinfo.getDeviceScreenSize(activity)[1]) || (sizes.get(i).width == Deviceinfo.getDeviceScreenSize(activity)[1] && sizes.get(i).height == Deviceinfo.getDeviceScreenSize(activity)[0])) { if (Deviceinfo.getDeviceScreenOrentation(activity).equals("portrait")) { PrintLog.print( activity.getApplicationContext(), sizes.get(i).width + "|" + sizes.get(i).height + " is support!"); params.setPictureSize(sizes.get(i).width, sizes.get(i).height); if (getFrontCameraStatus()) { // Front Facing Detect params.setPreviewSize(sizes.get(i).width, sizes.get(i).height); } if (getBackCameraStatus()) { // back Facing Detect params.setPreviewSize( Integer.parseInt(devicearraydata[4]), Integer.parseInt(devicearraydata[3])); } try { cam.setParameters(params); } catch (Exception e) { PrintLog.print(activity, "Can't setPictureSizeOfScreen"); } } sizesupportofscreen = true; break; } else { sizesupportofscreen = false; } } // // if(!sizesupportofscreen){ // params.setPreviewSize(1200,1600); // try{ // cam.setParameters(params); // }catch (Exception e){ // PrintLog.print(activity,"Can't setPictureSizeOfScreen"); // } // // } if (Deviceinfo.BUILD_MODEL.equals("GT-S5360")) { params.setPictureSize(1280, 960); try { cam.setParameters(params); } catch (Exception e) { PrintLog.print(activity, "Can't setPictureSizeOfScreen"); } } }