我的相机应用程序预览在低光照下太暗.如果我打开我的谷歌相机,它将增加预览内的亮度,以便我们的脸部可以拍照.但我的预览完全是黑暗的.我处理了亮度和光线传感器.我的Lightsensor工作时很轻.我需要让预览可见.让我知道我该怎么办?
public void initialBrightness() {
try {
brightnessMode = Settings.System.getInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE);
} catch (Settings.SettingNotFoundException e) {
e.printStackTrace();
}
if (brightnessMode == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC) {
Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE,
Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
brightnessModeAuto = true;
}
Settings.System.putInt(this.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, 95);
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = 100;
getWindow().setAttributes(lp);
}
Run Code Online (Sandbox Code Playgroud)
我在调用相机预览类之前在onCreate方法中调用此方法.
NullPointerException在OnPictureTakenMethod中获取一些手机.我正在调用像这样的takePicture方法.
mCamera.takePicture(shutterCallback, null, mPicture);
Run Code Online (Sandbox Code Playgroud)
我的OnPictureTaken方法
private Camera.PictureCallback mPicture = new Camera.PictureCallback() {
public void onPictureTaken(byte[] data, Camera camera) {
Bitmap bitmap = null;
if(flashOff) {
resetCamOnFlashOFF();
}
else {
resetCamOnFlashOn();
}
File sdDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
File dir = new File(sdDir.getAbsolutePath() + "/Camera2/");
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String fileName = "/IMG_" + timeStamp + ".jpeg";
boolean mkDir = dir.mkdirs();
Log.d("Saving Photo","Created the directory" +mkDir);
ExifInterface exif;
try {
exif = new ExifInterface(fileName);
exif.setAttribute(ExifInterface.TAG_ORIENTATION, "" …Run Code Online (Sandbox Code Playgroud)