如何通过Java从Android手机摄像头获得曝光补偿级别?
拍摄照片时,如何从Android手机获取自动曝光补偿级别(亮度)?
我可以拍照。我可以访问相机的参数,包括曝光补偿(检查时始终为零),但我需要在拍摄照片时获得AE补偿级别,而不是在拍摄之前和之后。
背景:我希望在特定时间拍摄的所有照片都使用与拍摄照片相同的AE补偿级别。我不希望Android相机通常对曝光水平或白平衡进行数百次调整。我想得到一次,并设置所有后续照片,相同的设置。
我尝试过对图片,OpenCV,片段等使用“意图”。我似乎无法获得其中任何一个的AE补偿设置。以下是我尝试过的最新代码,从JavaCameraView的扩展版本开始:
import org.opencv.android.JavaCameraView;
import android.content.Context;
import android.hardware.Camera;
import android.hardware.Camera.PictureCallback;
import android.hardware.Camera.Size;
import android.util.AttributeSet;
import android.util.Log;
@SuppressWarnings("deprecation")
public class NewJavaCameraView extends JavaCameraView implements PictureCallback {
public int getExposureCompensation(){
return mCamera.getParameters().getExposureCompensation();
}
@SuppressWarnings("deprecation")
public void takePicture(final String fileName) {
Log.i(TAG, "Taking picture");
this.mPictureFileName = fileName;
Camera.Parameters params = mCamera.getParameters();
int exposureComp = params.getExposureCompensation();
mCamera.setPreviewCallback(null);
// PictureCallback is implemented by the current class
int otherexposureComp =this.getExposureCompensation();
mCamera.takePicture(null, null, this);
}
@SuppressWarnings("deprecation")
@Override
public void onPictureTaken(byte[] data, Camera camera) {
Camera.Parameters params = mCamera.getParameters();
int exposureComp = params.getExposureCompensation();
int otherexposureComp =this.getExposureCompensation();
mCamera.startPreview();
mCamera.setPreviewCallback(this);
// Write the image in a file (in jpeg format)
try {
FileOutputStream fos = new FileOutputStream(mPictureFileName);
fos.write(data);
fos.close();
} catch (java.io.IOException e) {
Log.e("Picture", "photoCallback", e);
}
}
以下是 Android View 中使用上述类的一些代码:
public class DiscPhoto extends Activity implements CvCameraViewListener2, OnTouchListener {
private static final String TAG = "OCVSample::Activity";
private NewJavaCameraView mOpenCvCameraView;
private List<Size> mResolutionList;
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS:
{
Log.i(TAG, "OpenCV loaded successfully");
mOpenCvCameraView.enableView();
mOpenCvCameraView.setOnTouchListener(DiscPhoto.this);
} break;
default:
{
super.onManagerConnected(status);
} break;
}
}
};
public DiscPhoto() {
Log.i(TAG, "Instantiated new " + this.getClass());
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
Log.i(TAG, "called onCreate");
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.activity_disc_photo);
mOpenCvCameraView = (NewJavaCameraView) findViewById(R.id.discPhotoPage);
mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);
mOpenCvCameraView.setCvCameraViewListener(this);
}
@SuppressLint("SimpleDateFormat")
@Override
public boolean onTouch(View v, MotionEvent event) {
Log.i(TAG,"onTouch event");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
String currentDateandTime = sdf.format(new Date());
String fileName = Environment.getExternalStorageDirectory().getPath() +
"/sample_picture_" + currentDateandTime + ".jpg";
mOpenCvCameraView.takePicture(fileName);
Toast.makeText(this, fileName + " saved", Toast.LENGTH_SHORT).show();
return false;
}