List of usage examples for android.hardware Camera getParameters
public Parameters getParameters()
From source file:at.wada811.utils.CameraUtils.java
public static Size getPictureSize(Context context, Camera camera) { final List<Size> sizes = camera.getParameters().getSupportedPictureSizes(); final double ASPECT_TOLERANCE = 0.07; final boolean isPortrait = DisplayUtils.isPortrait(context); final int width = DisplayUtils.getWidth(context); final int height = DisplayUtils.getHeight(context); if (DEBUG) {//from w w w . j a v a 2s .c o m LogUtils.v("width: " + width); } if (DEBUG) { LogUtils.v("height: " + height); } final double targetRatio = isPortrait ? (double) height / width : (double) width / height; final int targetHeight = isPortrait ? width : height; Size optimalSize = null; double minDiff = Double.MAX_VALUE; if (DEBUG) { LogUtils.v("targetRatio: " + targetRatio); } for (Size size : sizes) { double pictureRatio = isPortrait ? (double) size.height / size.width : (double) size.width / size.height; pictureRatio = (double) size.width / size.height; if (DEBUG) { LogUtils.v("size.width: " + size.width); } if (DEBUG) { LogUtils.v("size.height: " + size.height); } if (DEBUG) { LogUtils.v("pictureRatio: " + pictureRatio); } if (Math.abs(pictureRatio - targetRatio) > ASPECT_TOLERANCE) { continue; } if (Math.abs(size.height - targetHeight) < minDiff) { optimalSize = size; minDiff = Math.abs(size.height - targetHeight); } } if (optimalSize == null) { minDiff = Double.MAX_VALUE; for (Size size : sizes) { if (Math.abs(size.height - targetHeight) < minDiff) { optimalSize = size; minDiff = Math.abs(size.height - targetHeight); } } } if (DEBUG) { LogUtils.v("optimalSize.width: " + optimalSize.width); } if (DEBUG) { LogUtils.v("optimalSize.height: " + optimalSize.height); } return optimalSize; }
From source file:at.wada811.utils.CameraUtils.java
/** * Returns the best preview size//from www.ja v a 2 s. c om * * @param context * @param camera */ public static Size getOptimalPreviewSize(Context context, Camera camera) { final List<Size> sizes = camera.getParameters().getSupportedPreviewSizes(); final double ASPECT_TOLERANCE = 0.07; final boolean isPortrait = DisplayUtils.isPortrait(context); final Size pictureSize = camera.getParameters().getPictureSize(); final int width = pictureSize.width; final int height = pictureSize.height; if (DEBUG) { LogUtils.v("width: " + width); } if (DEBUG) { LogUtils.v("height: " + height); } final double targetRatio = isPortrait ? (double) height / width : (double) width / height; final int targetHeight = isPortrait ? width : height; Size optimalSize = null; double minDiff = Double.MAX_VALUE; if (DEBUG) { LogUtils.v("targetRatio: " + targetRatio); } for (Size size : sizes) { double previewRatio = isPortrait ? (double) size.height / size.width : (double) size.width / size.height; previewRatio = (double) size.width / size.height; if (DEBUG) { LogUtils.v("size.width: " + size.width); } if (DEBUG) { LogUtils.v("size.height: " + size.height); } if (DEBUG) { LogUtils.v("previewRatio: " + previewRatio); } if (Math.abs(previewRatio - targetRatio) > ASPECT_TOLERANCE) { continue; } if (Math.abs(size.height - targetHeight) < minDiff) { optimalSize = size; minDiff = Math.abs(size.height - targetHeight); } } if (optimalSize == null) { minDiff = Double.MAX_VALUE; for (Size size : sizes) { if (Math.abs(size.height - targetHeight) < minDiff) { optimalSize = size; minDiff = Math.abs(size.height - targetHeight); } } } if (DEBUG) { LogUtils.v("optimalSize.width: " + optimalSize.width); } if (DEBUG) { LogUtils.v("optimalSize.height: " + optimalSize.height); } return optimalSize; }
From source file:at.wada811.utils.CameraUtils.java
/** * ????????/*from w w w .ja v a2 s . c o m*/ * * @param context * @param camera * @return scaledPreviewSize */ public static Size getScaledPreviewSize(Context context, Camera camera) { Size previewSize = camera.getParameters().getPreviewSize(); boolean isPortrait = DisplayUtils.isPortrait(context); final int displayWidth = DisplayUtils.getWidth(context); final int displayHeight = DisplayUtils.getHeight(context); if (DEBUG) { LogUtils.v("displayWidth: " + displayWidth); } if (DEBUG) { LogUtils.v("displayHeight: " + displayHeight); } PreferenceUtils.putInt(context, context.getString(R.string.keyDisplayWidth), displayWidth); PreferenceUtils.putInt(context, context.getString(R.string.keyDisplayHeight), displayHeight); final int previewWidth = isPortrait ? previewSize.height : previewSize.width; final int previewHeight = isPortrait ? previewSize.width : previewSize.height; if (DEBUG) { LogUtils.v("previewWidth: " + previewWidth); } if (DEBUG) { LogUtils.v("previewHeight: " + previewHeight); } PreferenceUtils.putInt(context, context.getString(R.string.keyPreviewWidth), previewWidth); PreferenceUtils.putInt(context, context.getString(R.string.keyPreviewHeight), previewHeight); double displayRatio = displayHeight > displayWidth ? (double) displayHeight / displayWidth : (double) displayWidth / displayHeight; double previewRatio = previewHeight > previewWidth ? (double) previewHeight / previewWidth : (double) previewWidth / previewHeight; if (DEBUG) { LogUtils.v("displayRatio: " + displayRatio); } if (DEBUG) { LogUtils.v("previewRatio: " + previewRatio); } PreferenceUtils.putFloat(context, context.getString(R.string.keyDisplayRatio), (float) displayRatio); PreferenceUtils.putFloat(context, context.getString(R.string.keyPreviewRatio), (float) previewRatio); int scaledChildWidth = displayWidth; int scaledChildHeight = displayHeight; if (displayRatio <= previewRatio) { if (isPortrait) { if (DEBUG) { LogUtils.v("Portrait"); } scaledChildWidth = (displayHeight * previewWidth) / previewHeight; scaledChildHeight = (scaledChildWidth * previewHeight) / previewWidth; } else { if (DEBUG) { LogUtils.v("Landscape"); } scaledChildHeight = (displayWidth * previewHeight) / previewWidth; scaledChildWidth = (scaledChildHeight * previewWidth) / previewHeight; } } else { if (isPortrait) { if (DEBUG) { LogUtils.v("Portrait"); } scaledChildHeight = (displayWidth * previewHeight) / previewWidth; scaledChildWidth = (scaledChildHeight * previewWidth) / previewHeight; } else { if (DEBUG) { LogUtils.v("Landscape"); } scaledChildWidth = (displayHeight * previewWidth) / previewHeight; scaledChildHeight = (scaledChildWidth * previewHeight) / previewWidth; } } if (DEBUG) { LogUtils.v("scaledChildWidth: " + scaledChildWidth); } if (DEBUG) { LogUtils.v("scaledChildHeight: " + scaledChildHeight); } PreferenceUtils.putInt(context, context.getString(R.string.keyScaledChildWidth), scaledChildWidth); PreferenceUtils.putInt(context, context.getString(R.string.keyScaledChildHeight), scaledChildHeight); int scaledWidth = scaledChildWidth; int scaledHeight = scaledChildHeight; if (displayRatio <= previewRatio) { if (isPortrait) { if (DEBUG) { LogUtils.v("Portrait"); } scaledHeight = (displayWidth * previewHeight) / previewWidth; scaledWidth = (scaledHeight * previewWidth) / previewHeight; } else { if (DEBUG) { LogUtils.v("Landscape"); } scaledWidth = (displayHeight * previewWidth) / previewHeight; scaledHeight = (scaledWidth * previewHeight) / previewWidth; } } else { if (isPortrait) { if (DEBUG) { LogUtils.v("Portrait"); // scaledWidth = (displayHeight * previewWidth) / previewHeight; // scaledHeight = (scaledWidth * previewHeight) / previewWidth; } } else { if (DEBUG) { LogUtils.v("Landscape"); // scaledHeight = (displayWidth * previewHeight) / previewWidth; // scaledWidth = (scaledHeight * previewWidth) / previewHeight; } } } if (DEBUG) { LogUtils.v("scaledWidth: " + scaledWidth); } if (DEBUG) { LogUtils.v("scaledHeight: " + scaledHeight); } PreferenceUtils.putInt(context, context.getString(R.string.keyScaledWidth), scaledWidth); PreferenceUtils.putInt(context, context.getString(R.string.keyScaledHeight), scaledHeight); return camera.new Size(scaledWidth, scaledHeight); }
From source file:at.wada811.utils.CameraUtils.java
/** * ???// w w w. j a va2s .co m */ @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) public static boolean isFaceDetectionSupported(Context context, Camera camera) { boolean isFaceDetectionSupported = false; int maxNumDetectedFaces = 0; if (AndroidUtils.isMoreThanBuildVersion(Build.VERSION_CODES.ICE_CREAM_SANDWICH)) { maxNumDetectedFaces = camera.getParameters().getMaxNumDetectedFaces(); isFaceDetectionSupported = maxNumDetectedFaces > 0; } PreferenceUtils.putBoolean(context, context.getString(R.string.keySupportFaceDetection), isFaceDetectionSupported); PreferenceUtils.putInt(context, context.getString(R.string.keyMaxNumDetectedFaces), maxNumDetectedFaces); return isFaceDetectionSupported; }
From source file:edu.mit.mobile.android.livingpostcards.CameraActivity.java
/** A safe way to get an instance of the Camera object. */ public static Camera getCameraInstance() { Camera c = null; try {// w w w . j a v a 2 s . c o m c = Camera.open(); // attempt to get a Camera instance final Parameters params = c.getParameters(); final Size s = getBestPictureSize(640, 480, params); params.setPictureSize(s.width, s.height); if (Constants.DEBUG) { Log.d(TAG, "best picture size is " + s.width + "x" + s.height); } c.setParameters(params); } catch (final Exception e) { Log.e(TAG, "Error acquiring camera", e); } return c; // returns null if camera is unavailable }
From source file:jp.maju.wifiserver.camera.QRReaderActivity.java
@Override public void onClick(View v) { switch (v.getId()) { case R.id.surface_camera: mCameraSurfaceView.oneShot(new PreviewCallback() { @Override/*ww w . j a v a2s. c o m*/ public void onPreviewFrame(byte[] data, Camera camera) { int previewWidth = camera.getParameters().getPreviewSize().width; int previewHeight = camera.getParameters().getPreviewSize().height; PlanarYUVLuminanceSource source = new PlanarYUVLuminanceSource(data, previewWidth, previewHeight, 0, 0, previewWidth, previewHeight, false); BinaryBitmap biBitmap = new BinaryBitmap(new HybridBinarizer(source)); Result result = null; try { result = new MultiFormatReader().decode(biBitmap); String text = result.getText(); String[] params = text.split(":"); if (CommonUtil.getCurrentSSID(getApplication()).equals(params[0])) { SocketInfo si = new SocketInfo(params[0]); si.setHost(params[1]); si.setPort(Integer.parseInt(params[2])); si.setKind(params[3]); Intent intent = new Intent(QRReaderActivity.this, ClientActivity.class) .putExtra(ClientActivity.KEY_SOCKET_INFO, si); intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); PreferenceUtil.save(getApplication(), si); PreferenceUtil.setDefaultSide(getApplication(), 2); startActivity(intent); finish(); } Logger.d(TAG, "Result decoded:" + text); } catch (Exception e) { Logger.e(TAG, e); Toast.makeText(getApplicationContext(), "Failed to read", Toast.LENGTH_SHORT).show(); } } }, 3); break; } }
From source file:com.dynamsoft.camera.DBR.java
@Override public void onPreviewFrame(byte[] data, Camera camera) { if (mFinished && !mIsDialogShowing) { mFinished = false;/*from ww w .j a va2s.co m*/ Camera.Size size = camera.getParameters().getPreviewSize(); mImageHeight = size.height; mBarcodeReader.readSingleAsync(data, size.width, size.height, mBarcodeFormat, new FinishCallback() { @Override public void onFinish(ReadResult readResult) { Message message = handler.obtainMessage(READ_RESULT, readResult); message.sendToTarget(); } }); } }
From source file:com.bringcommunications.etherpay.ScanActivity.java
public void onPreviewFrame(byte[] data, Camera camera) { if (!previewing || camera == null || mCamera == null) return;//from w w w. j a v a 2 s . c om Camera.Parameters parameters = camera.getParameters(); Size size = parameters.getPreviewSize(); Image barcode = new Image(size.width, size.height, "Y800"); barcode.setData(data); int result = scanner.scanImage(barcode); if (result != 0) { previewing = false; mCamera.setPreviewCallback(null); mCamera.stopPreview(); String scanned_data = "no data"; SymbolSet syms = scanner.getResults(); for (Symbol sym : syms) { //scanText.setText("barcode result " + sym.getData()); scanned_data = sym.getData(); barcodeScanned = true; } switch (target_activity) { case "SendActivity": { Intent intent = new Intent(this, SendActivity.class); //many QR codes simple contain the address, (eg 0x....); but i've seen this format also: //ethereum:<address>[?value=<value>][?gas=<suggestedGas>] String to_addr = scanned_data; if (scanned_data.contains(":0x")) { int addr_idx = scanned_data.indexOf(':') + 1; int end_idx = scanned_data.indexOf('?', addr_idx); to_addr = (end_idx < 0) ? scanned_data.substring(addr_idx) : scanned_data.substring(addr_idx, end_idx); } String size_str = "0"; if (scanned_data.contains("value=")) { int size_idx = scanned_data.indexOf("value=") + "value=".length() + 1; int end_idx = scanned_data.indexOf('?', size_idx); size_str = (end_idx < 0) ? scanned_data.substring(size_idx) : scanned_data.substring(size_idx, end_idx); } intent.putExtra("TO_ADDR", to_addr); intent.putExtra("SIZE", size_str); intent.putExtra("DATA", ""); intent.putExtra("AUTO_PAY", ""); //finish scanactivity so back key doesn't bring us back here System.out.println("ScanACtivity::onPreviewFrame -- starting SendActivity"); startActivity(intent); this.finish(); break; } case "MainActivity": { String app_uri = getResources().getString(R.string.app_uri); SharedPreferences preferences = getSharedPreferences(app_uri, MODE_PRIVATE); SharedPreferences.Editor preferences_editor = preferences.edit(); preferences_editor.putString("key", scanned_data); preferences_editor.commit(); NavUtils.navigateUpFromSameTask(this); this.finish(); break; } default: { System.out.println("TARGET_ACTIVITY not set in ScanActivity"); break; } } } }
From source file:com.dynamsoft.demo.dynamsoftbarcodereaderdemo.DBR.java
@Override public void onPreviewFrame(byte[] data, Camera camera) { if (isFirstTime) { isFirstTime = false;/*from ww w.j av a 2 s. c o m*/ Log.i("xiao", "width: " + camera.getParameters().getPreviewSize().width + ", height: " + camera.getParameters().getPreviewSize().height); try { File file = new File(Environment.getExternalStorageDirectory() + "/tmp.yuv"); Log.i("xiao", "path: " + file.getAbsolutePath()); FileOutputStream output = new FileOutputStream(file); output.write(data); output.flush(); output.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } if (mFinished && !mIsDialogShowing) { mFinished = false; //mStartTime = SystemClock.currentThreadTimeMillis(); mStartTime = new Date().getTime(); Camera.Size size = camera.getParameters().getPreviewSize(); try { TextResult[] readResult = mBarcodeReader.decodeBuffer(data, size.width, size.height, size.width, EnumImagePixelFormat.IPF_NV21, ""); Message message = handler.obtainMessage(READ_RESULT, readResult); message.sendToTarget(); } catch (BarcodeReaderException e) { e.printStackTrace(); } } }
From source file:com.androchill.call411.MainActivity.java
private Phone getHardwareSpecs() { ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE); PhoneBuilder pb = new PhoneBuilder(); pb.setModelNumber(Build.MODEL);/*from ww w . j a va 2 s.c o m*/ pb.setManufacturer(Build.MANUFACTURER); Process p = null; String board_platform = "No data available"; try { p = new ProcessBuilder("/system/bin/getprop", "ro.chipname").redirectErrorStream(true).start(); BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = ""; while ((line = br.readLine()) != null) { board_platform = line; } p.destroy(); } catch (IOException e) { e.printStackTrace(); board_platform = "No data available"; } pb.setProcessor(board_platform); ActivityManager.MemoryInfo mInfo = new ActivityManager.MemoryInfo(); activityManager.getMemoryInfo(mInfo); pb.setRam((int) (mInfo.totalMem / 1048576L)); pb.setBatteryCapacity(getBatteryCapacity()); pb.setTalkTime(-1); pb.setDimensions("No data available"); WindowManager mWindowManager = getWindowManager(); Display mDisplay = mWindowManager.getDefaultDisplay(); Point mPoint = new Point(); mDisplay.getSize(mPoint); pb.setScreenResolution(mPoint.x + " x " + mPoint.y + " pixels"); DisplayMetrics mDisplayMetrics = new DisplayMetrics(); mDisplay.getMetrics(mDisplayMetrics); int mDensity = mDisplayMetrics.densityDpi; pb.setScreenSize( Math.sqrt(Math.pow(mPoint.x / (double) mDensity, 2) + Math.pow(mPoint.y / (double) mDensity, 2))); Camera camera = Camera.open(0); android.hardware.Camera.Parameters params = camera.getParameters(); List sizes = params.getSupportedPictureSizes(); Camera.Size result = null; ArrayList<Integer> arrayListForWidth = new ArrayList<Integer>(); ArrayList<Integer> arrayListForHeight = new ArrayList<Integer>(); for (int i = 0; i < sizes.size(); i++) { result = (Camera.Size) sizes.get(i); arrayListForWidth.add(result.width); arrayListForHeight.add(result.height); } if (arrayListForWidth.size() != 0 && arrayListForHeight.size() != 0) { pb.setCameraMegapixels( Collections.max(arrayListForHeight) * Collections.max(arrayListForWidth) / (double) 1000000); } else { pb.setCameraMegapixels(-1); } camera.release(); pb.setPrice(-1); pb.setWeight(-1); pb.setSystem("Android " + Build.VERSION.RELEASE); StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath()); StatFs statInternal = new StatFs(Environment.getRootDirectory().getAbsolutePath()); double storageSize = ((stat.getBlockSizeLong() * stat.getBlockCountLong()) + (statInternal.getBlockSizeLong() * statInternal.getBlockCountLong())) / 1073741824L; pb.setStorageOptions(storageSize + " GB"); TelephonyManager telephonyManager = ((TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE)); String operatorName = telephonyManager.getNetworkOperatorName(); if (operatorName.length() == 0) operatorName = "No data available"; pb.setCarrier(operatorName); pb.setNetworkFrequencies("No data available"); pb.setImage(null); return pb.createPhone(); }