我正在Xamarin Android中创建一个应用。用户界面是一个按钮,只需单击即可拍摄照片,但不会显示预览。用于拍摄照片和相机设置的代码:
private void TakePhotoButton_Click(object sender, EventArgs e)
{
camera = Open();
try
{
camera.SetPreviewTexture(new SurfaceTexture(10));
}
catch (IOException e1)
{
//Log.e(Version.APP_ID, e1.getMessage());
}
Parameters newParameters = GetModifiedCameraParameters();
camera.SetParameters(newParameters);
camera.StartPreview();
camera.TakePicture(null, null, new PictureCallback());
}
private Parameters GetModifiedCameraParameters()
{
Parameters parameters = camera.GetParameters();
Size size = FindMaxSize(parameters.SupportedPictureSizes);
parameters.SetPreviewSize(640, 480);
parameters.SetPictureSize(size.Width, size.Height);
parameters.Set("contrast", "0");
parameters.FlashMode = Parameters.FlashModeOff;
parameters.FocusMode = Parameters.FocusModeAuto;
parameters.SceneMode = Parameters.SceneModeAuto;
parameters.AutoExposureLock = false;
parameters.WhiteBalance = Parameters.WhiteBalanceAuto;
parameters.ExposureCompensation = 12;
parameters.PictureFormat = ImageFormat.Jpeg;
parameters.JpegQuality = 100;
parameters.SetRotation(90);
return parameters;
}
private Size FindMaxSize(IList<Size> sizes)
{
Size[] orderByDescending = sizes
.OrderByDescending(x => x.Width)
.ToArray();
return orderByDescending[0];
}
结果是高质量的照片,但亮度低。我尝试更改曝光,ISO。真正增加了照片对比度的亮度变化。但是照片仍然不够亮。清单文件如下:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.companyname.workwithcamera" android:installLocation="auto">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="24" />
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher_round" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
</manifest>
相机参数中没有设置亮度的方法,可以使用媒体插件。
该示例适用于xamarin.forms android。https://github.com/jamesmontemagno/MediaPlugin
您可以手动增加亮度。