public static boolean isFlashSupported(Camera camera, Context context) { mPreferences = PreferenceManager.getDefaultSharedPreferences(context); if (camera != null) { Camera.Parameters mParameters = camera.getParameters(); if (mParameters.getFlashMode() == null) { mPrefFlash = mPreferences.edit().putBoolean("mPrefFlash", false).commit(); return false; } List<String> mSupportedFlashModes = mParameters.getSupportedFlashModes(); if (mSupportedFlashModes == null || mSupportedFlashModes.isEmpty() || mSupportedFlashModes.size() == 1 && mSupportedFlashModes.get(0).equals(Camera.Parameters.FLASH_MODE_OFF)) { mPrefFlash = mPreferences.edit().putBoolean("mPrefFlash", false).commit(); return false; } } else { mPrefFlash = mPreferences.edit().putBoolean("mPrefFlash", false).commit(); return false; } mPrefFlash = mPreferences.edit().putBoolean("mPrefFlash", true).commit(); return true; }
public void offLight() { if (camera != null) { Camera.Parameters parameter = camera.getParameters(); parameter.setFlashMode(Camera.Parameters.FLASH_MODE_OFF); camera.setParameters(parameter); } }
public static void setBestPreviewFPS(Camera.Parameters parameters, int minFPS, int maxFPS) { List<int[]> supportedPreviewFpsRanges = parameters.getSupportedPreviewFpsRange(); Log.i(TAG, "Supported FPS ranges: " + toString(supportedPreviewFpsRanges)); if (supportedPreviewFpsRanges != null && !supportedPreviewFpsRanges.isEmpty()) { int[] suitableFPSRange = null; for (int[] fpsRange : supportedPreviewFpsRanges) { int thisMin = fpsRange[Camera.Parameters.PREVIEW_FPS_MIN_INDEX]; int thisMax = fpsRange[Camera.Parameters.PREVIEW_FPS_MAX_INDEX]; if (thisMin >= minFPS * 1000 && thisMax <= maxFPS * 1000) { suitableFPSRange = fpsRange; break; } } if (suitableFPSRange == null) { Log.i(TAG, "No suitable FPS range?"); } else { int[] currentFpsRange = new int[2]; parameters.getPreviewFpsRange(currentFpsRange); if (Arrays.equals(currentFpsRange, suitableFPSRange)) { Log.i(TAG, "FPS range already set to " + Arrays.toString(suitableFPSRange)); } else { Log.i(TAG, "Setting FPS range to " + Arrays.toString(suitableFPSRange)); parameters.setPreviewFpsRange( suitableFPSRange[Camera.Parameters.PREVIEW_FPS_MIN_INDEX], suitableFPSRange[Camera.Parameters.PREVIEW_FPS_MAX_INDEX]); } } } }
@Override public void setPreviewHeight(int mPreviewHeight) { this.mPreviewHeight = mPreviewHeight; Camera.Parameters parameters = mCamera.getParameters(); // 设置预览照片的大小 parameters.setPreviewSize(mPreviewWidth, mPreviewHeight); }
@Override public void onPreviewFrame(byte[] data, Camera camera) { Camera.Parameters params = camera.getParameters(); int w = params.getPreviewSize().width; int h = params.getPreviewSize().height; int format = params.getPreviewFormat(); ByteArrayOutputStream out = new ByteArrayOutputStream(); YuvImage image = new YuvImage(data, format, w, h, null); Rect area = new Rect(0, 0, w, h); long start = System.currentTimeMillis(); image.compressToJpeg(area, imageQuality, out); long end = System.currentTimeMillis(); long pingTime = ServerConnector.getInstance().getPingTime() + (end - start); if (pingTime > 50 && imageQuality > 25) { imageQuality--; } else if (pingTime < 50 && imageQuality < 100) { imageQuality++; } Log.i("image", "" + imageQuality); ServerConnector.getInstance().pushImage(out.toByteArray()); }
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Hide the window title. requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); getWindow().setFormat(PixelFormat.UNKNOWN); setContentView(R.layout.main); // Create an instance of Camera mCamera = getCameraInstance(); Camera.Parameters mParameters = mCamera.getParameters(); mParameters.setFlashMode(Camera.Parameters.FLASH_MODE_AUTO); // mParameters.setFlashMode(Camera.Parameters.FLASH_MODE_ON); mCamera.setParameters(mParameters); // Create our Preview view and set it as the content of our activity. mPreview = new Preview(this, mCamera); FrameLayout preview = (FrameLayout) findViewById(R.id.preview); preview.addView(mPreview); // Create our Overlay mOverlay = new Overlay(this); preview.addView(mOverlay); mPreview.setOverlay(mOverlay); // Setting buttons buttonProc = (Button) findViewById(R.id.buttonProc); buttonBinImage = (Button) findViewById(R.id.buttonBinaryImage); buttonReset = (Button) findViewById(R.id.buttonReset); buttonProc.setOnClickListener(snapAndProcess()); buttonBinImage.setOnClickListener(switchBinaryImage()); buttonReset.setOnClickListener(reset()); }
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { Log.e(TAG, "surfaceChanged => w=" + w + ", h=" + h); // If your preview can change or rotate, take care of those events here. // Make sure to stop the preview before resizing or reformatting it. if (mHolder.getSurface() == null) { // preview surface does not exist return; } // stop preview before making changes try { mCamera.stopPreview(); } catch (Exception e) { // ignore: tried to stop a non-existent preview } // set preview size and make any resize, rotate or reformatting changes here // start preview with new settings try { Camera.Parameters parameters = mCamera.getParameters(); /* INSERT ZOOM HERE */ parameters.setPreviewSize(mPreviewSize.width, mPreviewSize.height); parameters.setRotation(90); mCamera.setParameters(parameters); mCamera.setDisplayOrientation(90); mCamera.setPreviewDisplay(mHolder); mCamera.startPreview(); } catch (Exception e) { Log.d(TAG, "Error starting camera preview: " + e.getMessage()); } }
private void setPreviewCallback() { if (mCamera == null) { android.util.Log.e("MOSYNC INTERNAL", "No Preview set"); return; } try { // We have to use and static instance of the camera in the reflection here mSetPreviewCallbackWithBuffer = mCamera .getClass() .getMethod("setPreviewCallbackWithBuffer", Camera.PreviewCallback.class); Camera.Parameters parameters = getCurrentParameters(); Camera.Size size = parameters.getPreviewSize(); mCallbackBuffer = new byte[size.width * size.height * 4]; mCamera.addCallbackBuffer(mCallbackBuffer); mIsUsingPreviewCallbackBuffer = true; mCamera.setPreviewCallbackWithBuffer(previewCallback); } catch (NoSuchMethodException nsme) { mIsUsingPreviewCallbackBuffer = false; mCamera.setPreviewCallback(previewCallback); } }
@Override public void surfaceCreated(SurfaceHolder holder) { try { // open the camera camera = Camera.open(1); } catch (RuntimeException e) { // check for exceptions System.err.println(e); return; } Camera.Parameters param; param = camera.getParameters(); // modify parameter param.setPreviewSize(352, 288); camera.setParameters(param); try { // The Surface has been created, now tell the camera where to draw // the preview. camera.setPreviewDisplay(surfaceHolder); camera.setDisplayOrientation(90); camera.startPreview(); } catch (Exception e) { // check for exceptions System.err.println(e); return; } }
@Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { if (mHolder.getSurface() == null) { // preview surface does not exist return; } // stop preview before making changes try { mCamera.stopPreview(); } catch (Exception e) { // ignore: tried to stop a non-existent preview } // Sets preview size. Camera.Parameters parameters = mCamera.getParameters(); List<Camera.Size> sizes = parameters.getSupportedPreviewSizes(); Camera.Size cs = sizes.get(0); parameters.setPreviewSize(cs.width, cs.height); mCamera.setParameters(parameters); // start preview with new settings try { mCamera.setPreviewDisplay(mHolder); mCamera.startPreview(); } catch (Exception e) { Log.d(TAG, "Error starting camera preview: " + e.getMessage()); } Log.e(TAG, "SurfaceChanged."); }
private void doSetTorch(Camera.Parameters parameters, boolean newSetting, boolean safeMode) { String flashMode; if (newSetting) { flashMode = findSettableValue( parameters.getSupportedFlashModes(), Camera.Parameters.FLASH_MODE_TORCH, Camera.Parameters.FLASH_MODE_ON); } else { flashMode = findSettableValue(parameters.getSupportedFlashModes(), Camera.Parameters.FLASH_MODE_OFF); } if (flashMode != null) { parameters.setFlashMode(flashMode); } /* * SharedPreferences prefs = * PreferenceManager.getDefaultSharedPreferences(context); if * (!prefs.getBoolean(PreferencesActivity.KEY_DISABLE_EXPOSURE, false)) * { if (!safeMode) { int minExposure = * parameters.getMinExposureCompensation(); int maxExposure = * parameters.getMaxExposureCompensation(); if (minExposure != 0 || * maxExposure != 0) { float step = * parameters.getExposureCompensationStep(); int desiredCompensation; if * (newSetting) { // Light on; set low exposue compensation * desiredCompensation = Math.max((int) (MIN_EXPOSURE_COMPENSATION / * step), minExposure); } else { // Light off; set high compensation * desiredCompensation = Math.min((int) (MAX_EXPOSURE_COMPENSATION / * step), maxExposure); } Log.i(TAG, "Setting exposure compensation to " * + desiredCompensation + " / " + (step * desiredCompensation)); * parameters.setExposureCompensation(desiredCompensation); } else { * Log.i(TAG, "Camera does not support exposure compensation"); } } } */ }
/** * Attempts to find a preview size that matches the provided width and height (which specify the * dimensions of the encoded video). If it fails to find a match it just uses the default preview * size. * * <p>TODO: should do a best-fit match. */ private static void choosePreviewSize(Camera.Parameters parms, int width, int height) { // We should make sure that the requested MPEG size is less than the preferred // size, and has the same aspect ratio. Camera.Size ppsfv = parms.getPreferredPreviewSizeForVideo(); if (ppsfv != null) { Log.d(TAG, "Camera preferred preview size for video is " + ppsfv.width + "x" + ppsfv.height); } // for (Camera.Size size : parms.getSupportedPreviewSizes()) { // Log.d(TAG, "supported: " + size.width + "x" + size.height); // } for (Camera.Size size : parms.getSupportedPreviewSizes()) { if (size.width == width && size.height == height) { parms.setPreviewSize(width, height); return; } } Log.w(TAG, "Unable to set preview size to " + width + "x" + height); if (ppsfv != null) { parms.setPreviewSize(ppsfv.width, ppsfv.height); } // else use whatever the default size is }
// Constructor public AudioSynth( final Camera camera, AudioTrack redSynthesizer, AudioTrack greenSynthesizer, AudioTrack blueSynthesizer) { mFinished = false; mRGBData = null; mRedSynthesizer = redSynthesizer; mGreenSynthesizer = greenSynthesizer; mBlueSynthesizer = blueSynthesizer; redGeneratedSnd = new short[maxSamples]; greenGeneratedSnd = new short[maxSamples]; blueGeneratedSnd = new short[maxSamples]; mRedHistogram = new int[256]; mGreenHistogram = new int[256]; mBlueHistogram = new int[256]; mBinSquared = new double[256]; for (int bin = 0; bin < 256; bin++) { mBinSquared[bin] = ((double) bin) * bin; } Camera.Parameters params = camera.getParameters(); mImageWidth = params.getPreviewSize().width; mImageHeight = params.getPreviewSize().height; int yStride = (int) Math.ceil(mImageWidth / 16.0) * 16; int uvStride = (int) Math.ceil((yStride / 2) / 16.0) * 16; int ySize = yStride * mImageHeight; int uvSize = uvStride * mImageHeight / 2; final int size = ySize + uvSize * 2; mYUVBuffer = new byte[size]; camera.addCallbackBuffer(mYUVBuffer); mRGBData = new int[mImageWidth * mImageHeight]; }
public void setupCameraParameters() { Camera.Size optimalSize = getOptimalPreviewSize(); Camera.Parameters parameters = mCamera.getParameters(); parameters.setPreviewSize(optimalSize.width, optimalSize.height); mCamera.setParameters(parameters); adjustViewSize(optimalSize); }
// Called when holder has changed public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { Camera.Parameters parameters = camera.getParameters(); List<String> focusModes = parameters.getSupportedFocusModes(); if (focusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO)) { Log.d("camera", "focus_mode_auto"); parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO); } else { Log.d("camera", "focus_mode_macro"); parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_MACRO); } Log.d("camera", "orientation: " + getResources().getConfiguration().orientation); int orientation = getResources().getConfiguration().orientation; switch (orientation) { case Surface.ROTATION_0: Log.d("camera", "ROTATION_0"); camera.setDisplayOrientation(180); break; case Surface.ROTATION_90: Log.d("camera", "ROTATION_90"); camera.setDisplayOrientation(90); break; case Surface.ROTATION_180: Log.d("camera", "ROTATION_180"); camera.setDisplayOrientation(0); break; case Surface.ROTATION_270: Log.d("camera", "ROTATION_270"); camera.setDisplayOrientation(270); break; } camera.setParameters(parameters); camera.startPreview(); }
/** Reads, one time, values from the camera that are needed by the app. */ void initFromCameraParameters(Camera camera) { Camera.Parameters parameters = camera.getParameters(); previewFormat = parameters.getPreviewFormat(); previewFormatString = parameters.get("preview-format"); Log.d(TAG, "Default preview format: " + previewFormat + '/' + previewFormatString); WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = manager.getDefaultDisplay(); screenResolution = new Point(display.getWidth(), display.getHeight()); Log.d(TAG, "Screen resolution: " + screenResolution); // ���һЩ�ֻ���ɨ���BUG����������i9228��i9220. Point screenResolutionForCamera = new Point(); screenResolutionForCamera.x = screenResolution.x; screenResolutionForCamera.y = screenResolution.y; // preview size is always something like 480*320, other 320*480 if (screenResolution.x < screenResolution.y) { screenResolutionForCamera.x = screenResolution.y; screenResolutionForCamera.y = screenResolution.x; } cameraResolution = getCameraResolution(parameters, screenResolutionForCamera); // cameraResolution = getCameraResolution(parameters, screenResolution); Log.d(TAG, "Camera resolution: " + screenResolution); }
public void onPreviewFrame(byte[] data, Camera camera) { Camera.Parameters parameters = camera.getParameters(); width = parameters.getPreviewSize().width; height = parameters.getPreviewSize().height; yuvImage = new YuvImage(data, ImageFormat.NV21, width, height, null); looped += 1; }
public void setCaptureQuality(int cameraType, String captureQuality) { Camera camera = _cameras.get(cameraType); if (camera == null) { return; } Camera.Parameters parameters = camera.getParameters(); Camera.Size pictureSize = null; switch (captureQuality) { case RCTCameraModule.RCT_CAMERA_CAPTURE_QUALITY_LOW: pictureSize = getSmallestSize(parameters.getSupportedPictureSizes()); break; case RCTCameraModule.RCT_CAMERA_CAPTURE_QUALITY_MEDIUM: List<Camera.Size> sizes = parameters.getSupportedPictureSizes(); pictureSize = sizes.get(sizes.size() / 2); break; case RCTCameraModule.RCT_CAMERA_CAPTURE_QUALITY_HIGH: pictureSize = getBestSize( parameters.getSupportedPictureSizes(), Integer.MAX_VALUE, Integer.MAX_VALUE); } if (pictureSize != null) { parameters.setPictureSize(pictureSize.width, pictureSize.height); camera.setParameters(parameters); } }
private static Point getCameraResolution(Camera.Parameters parameters, Point screenResolution) { String previewSizeValueString = parameters.get("preview-size-values"); // saw this on Xperia if (previewSizeValueString == null) { previewSizeValueString = parameters.get("preview-size-value"); } Point cameraResolution = null; if (CameraManager.mDesiredWidth == 0) CameraManager.mDesiredWidth = screenResolution.x; if (CameraManager.mDesiredHeight == 0) CameraManager.mDesiredHeight = screenResolution.y; List<Size> sizes = parameters.getSupportedPreviewSizes(); int minDif = 99999; int minIndex = -1; for (int i = 0; i < sizes.size(); i++) { int dif = Math.abs(sizes.get(i).width - CameraManager.mDesiredWidth) + Math.abs(sizes.get(i).height - CameraManager.mDesiredHeight); if (dif < minDif) { minDif = dif; minIndex = i; } } cameraResolution = new Point(sizes.get(minIndex).width, sizes.get(minIndex).height); // cameraResolution = findBestPreviewSizeValue(previewSizeValueString, // screenResolution); return cameraResolution; }
public void setFlashMode(int cameraType, int flashMode) { Camera camera = _cameras.get(cameraType); if (null == camera) { return; } Camera.Parameters parameters = camera.getParameters(); String value = parameters.getFlashMode(); switch (flashMode) { case RCTCameraModule.RCT_CAMERA_FLASH_MODE_AUTO: value = Camera.Parameters.FLASH_MODE_AUTO; break; case RCTCameraModule.RCT_CAMERA_FLASH_MODE_ON: value = Camera.Parameters.FLASH_MODE_ON; break; case RCTCameraModule.RCT_CAMERA_FLASH_MODE_OFF: value = Camera.Parameters.FLASH_MODE_OFF; break; } List<String> flashModes = parameters.getSupportedFlashModes(); if (flashModes != null && flashModes.contains(value)) { parameters.setFlashMode(value); camera.setParameters(parameters); } }
private void checkRearCamera() { Camera camera = null; try { camera = Camera.open(); if (camera != null) { assertAvailable(PackageManager.FEATURE_CAMERA); Camera.Parameters params = camera.getParameters(); if (params.getSupportedFocusModes().contains(Parameters.FOCUS_MODE_AUTO)) { assertAvailable(PackageManager.FEATURE_CAMERA_AUTOFOCUS); } else { assertNotAvailable(PackageManager.FEATURE_CAMERA_AUTOFOCUS); } if (params.getFlashMode() != null) { assertAvailable(PackageManager.FEATURE_CAMERA_FLASH); } else { assertNotAvailable(PackageManager.FEATURE_CAMERA_FLASH); } } else { assertNotAvailable(PackageManager.FEATURE_CAMERA); assertNotAvailable(PackageManager.FEATURE_CAMERA_AUTOFOCUS); assertNotAvailable(PackageManager.FEATURE_CAMERA_FLASH); } } finally { if (camera != null) { camera.release(); } } }
public int doZoom(float scale) { synchronized (mCameraLock) { if (mCamera == null) { return 0; } int currentZoom = 0; int maxZoom; Camera.Parameters parameters = mCamera.getParameters(); if (!parameters.isZoomSupported()) { Log.w(TAG, mContext.getString(R.string.zoom_not_supported)); return currentZoom; } maxZoom = parameters.getMaxZoom(); currentZoom = parameters.getZoom() + 1; float newZoom; if (scale > 1) { newZoom = currentZoom + scale * (maxZoom / 10); } else { newZoom = currentZoom * scale; } currentZoom = Math.round(newZoom) - 1; if (currentZoom < 0) { currentZoom = 0; } else if (currentZoom > maxZoom) { currentZoom = maxZoom; } parameters.setZoom(currentZoom); mCamera.setParameters(parameters); return currentZoom; } }
private static Point getCameraResolution(Camera.Parameters parameters, Point screenResolution) { String previewSizeValueString = parameters.get("preview-size-values"); // saw this on Xperia if (previewSizeValueString == null) { previewSizeValueString = parameters.get("preview-size-value"); } Point cameraResolution = null; if (previewSizeValueString != null) { Log.d(TAG, "preview-size-values parameter: " + previewSizeValueString); Log.d(TAG, "preview-size-values parameter: " + previewSizeValueString); cameraResolution = findBestPreviewSizeValue(previewSizeValueString, screenResolution); // cameraResolution = new Point(1280, 720); Log.d(TAG, "BestPreviewSizeValue: " + cameraResolution); } if (cameraResolution == null) { // Ensure that the camera resolution is a multiple of 8, as the screen may not be. cameraResolution = new Point((screenResolution.x >> 3) << 3, (screenResolution.y >> 3) << 3); } return cameraResolution; }
/** * Generates a list of acceptable preview sizes. Preview sizes are not acceptable if there is not * a corresponding picture size of the same aspect ratio. If there is a corresponding picture size * of the same aspect ratio, the picture size is paired up with the preview size. * * <p>This is necessary because even if we don't use still pictures, the still picture size must * be set to a size that is the same aspect ratio as the preview size we choose. Otherwise, the * preview images may be distorted on some devices. */ private static List<SizePair> generateValidPreviewSizeList(Camera camera, Context context) { Camera.Parameters parameters = camera.getParameters(); List<Camera.Size> supportedPreviewSizes = parameters.getSupportedPreviewSizes(); List<Camera.Size> supportedPictureSizes = parameters.getSupportedPictureSizes(); List<SizePair> validPreviewSizes = new ArrayList<>(); for (Camera.Size previewSize : supportedPreviewSizes) { float previewAspectRatio = (float) previewSize.width / (float) previewSize.height; // By looping through the picture sizes in order, we favor the higher resolutions. // We choose the highest resolution in order to support taking the full resolution // picture later. for (Camera.Size pictureSize : supportedPictureSizes) { float pictureAspectRatio = (float) pictureSize.width / (float) pictureSize.height; if (Math.abs(previewAspectRatio - pictureAspectRatio) < ASPECT_RATIO_TOLERANCE) { validPreviewSizes.add(new SizePair(previewSize, pictureSize)); break; } } } // If there are no picture sizes with the same aspect ratio as any preview sizes, allow all // of the preview sizes and hope that the camera can handle it. Probably unlikely, but we // still account for it. if (validPreviewSizes.size() == 0) { Log.w(TAG, context.getString(R.string.no_same_Aspect_ratio)); for (Camera.Size previewSize : supportedPreviewSizes) { // The null picture size will let us know that we shouldn't set a picture size. validPreviewSizes.add(new SizePair(previewSize, null)); } } return validPreviewSizes; }
public void onPreviewFrame(byte[] data, Camera camera) { Camera.Parameters parameters = camera.getParameters(); Camera.Size size = parameters.getPreviewSize(); Image barcode = new Image(size.width, size.height, "Y800"); barcode.setData(data); int result = mScanner.scanImage(barcode); if (result != 0) { mCamera.cancelAutoFocus(); mCamera.setPreviewCallback(null); mCamera.stopPreview(); mPreviewing = false; SymbolSet syms = mScanner.getResults(); for (Symbol sym : syms) { String symData = sym.getData(); if (!TextUtils.isEmpty(symData)) { Intent dataIntent = new Intent(); dataIntent.putExtra(SCAN_RESULT, symData); dataIntent.putExtra(SCAN_RESULT_TYPE, sym.getType()); setResult(Activity.RESULT_OK, dataIntent); finish(); break; } } } }
private void doSetTorch(Camera.Parameters parameters, boolean newSetting, boolean safeMode) { String flashMode; if (newSetting) { flashMode = findSettableValue( parameters.getSupportedFlashModes(), Camera.Parameters.FLASH_MODE_TORCH, Camera.Parameters.FLASH_MODE_ON); } else { flashMode = findSettableValue(parameters.getSupportedFlashModes(), Camera.Parameters.FLASH_MODE_OFF); } if (flashMode != null) { parameters.setFlashMode(flashMode); } /* SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); if (!prefs.getBoolean(PreferencesActivity.KEY_DISABLE_EXPOSURE, false)) { if (!safeMode) { ExposureInterface exposure = new ExposureManager().build(); exposure.setExposure(parameters, newSetting); } } */ }
public VideoHdrWidget(CameraManager cam, Context context) { super(cam, context, R.drawable.ic_widget_placeholder); // TODO: Icon, video hdr setVideoOnly(true); // We cannot inflate from XML here, because there are device-specific keys and values Camera.Parameters params = mCamManager.getParameters(); if (params == null) { return; } if (params.get(KEY_SONY_VIDEO_HDR) != null) { // Use Sony values setKey(KEY_SONY_VIDEO_HDR); addValue("off", R.drawable.ic_widget_hdr_off, context.getString(R.string.disabled)); addValue("on", R.drawable.ic_widget_hdr_on, context.getString(R.string.enabled)); } else if (params.get(KEY_QCOM_VIDEO_HDR) != null) { // Use Qcom values setKey(KEY_QCOM_VIDEO_HDR); addValue("0", R.drawable.ic_widget_hdr_off, context.getString(R.string.disabled)); addValue("1", R.drawable.ic_widget_hdr_on, context.getString(R.string.enabled)); } getToggleButton().setHintText(R.string.widget_videohdr); }
private void initCamera() { if (!isPreview) { camera = Camera.open(); } if (camera != null && !isPreview) { streamIt = new StreamIt(); try { Camera.Parameters parameters = camera.getParameters(); parameters.setPreviewSize(screenWidth, screenHeight); // 设置预览照片的大小 parameters.setPreviewFpsRange(20, 30); // 每秒显示20~30帧 parameters.setPictureFormat(ImageFormat.NV21); // 设置图片格式 parameters.setPictureSize(screenWidth, screenHeight); // 设置照片的大小 camera.setPreviewDisplay(surfaceHolder); // 通过SurfaceView显示取景画面 camera.setPreviewCallback(streamIt); // 设置回调的类 camera.startPreview(); // 开始预览 camera.autoFocus(null); // 自动对焦 } catch (Exception e) { e.printStackTrace(); } isPreview = true; Thread postThread2 = new Thread(new postThread()); postThread2.start(); System.out.println("线程启动了@@@@@@@@@@@@@@@@@@@@@@@@@@"); } }
public static void setBestExposure(Camera.Parameters parameters, boolean lightOn) { int minExposure = parameters.getMinExposureCompensation(); int maxExposure = parameters.getMaxExposureCompensation(); float step = parameters.getExposureCompensationStep(); if ((minExposure != 0 || maxExposure != 0) && step > 0.0f) { // Set low when light is on float targetCompensation = lightOn ? MIN_EXPOSURE_COMPENSATION : MAX_EXPOSURE_COMPENSATION; int compensationSteps = Math.round(targetCompensation / step); float actualCompensation = step * compensationSteps; // Clamp value: compensationSteps = Math.max(Math.min(compensationSteps, maxExposure), minExposure); if (parameters.getExposureCompensation() == compensationSteps) { Log.i( TAG, "Exposure compensation already set to " + compensationSteps + " / " + actualCompensation); } else { Log.i( TAG, "Setting exposure compensation to " + compensationSteps + " / " + actualCompensation); parameters.setExposureCompensation(compensationSteps); } } else { Log.i(TAG, "Camera does not support exposure compensation"); } }
@Override public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i2, int i3) { Log.e("ok", "surfaceChanged => w=" + i2 + ", h=" + i3); // before changing the application orientation, you need to stop the preview, rotate and then // start it again if (surfaceHolder.getSurface() == null) // check if the surface is ready to receive camera data return; try { mCamera.stopPreview(); } catch (Exception e) { // this will happen when you are trying the camera if it's not running } // now, recreate the camera preview try { Camera.Parameters parameters = mCamera.getParameters(); List<String> focusModes = parameters.getSupportedFocusModes(); if (focusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) { parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO); } parameters.setPreviewSize(mPreviewSize.width, mPreviewSize.height); mCamera.setParameters(parameters); mCamera.setDisplayOrientation(90); mCamera.startPreview(mHolder); } catch (IOException e) { Log.d("ERROR", "Camera error on surfaceChanged " + e.getMessage()); } }