我已经在Xamarin Visual Studio中完成了一个自定义相机应用程序,它以非常低的分辨率拍摄照片,因此我添加了这段代码.
public void OnSurfaceTextureAvailable(Android.Graphics.SurfaceTexture surface, int w, int h)
{
_camera = Android.Hardware.Camera.Open();
Android.Hardware.Camera.Parameters param = _camera.GetParameters();
IList<Android.Hardware.Camera.Size> supportedSizes = param.SupportedPictureSizes;
Android.Hardware.Camera.Size sizePicture = supportedSizes[0];
param.SetPictureSize(sizePicture.Height, sizePicture.Width);
_camera.SetParameters(param);
var previewSize = _camera.GetParameters().PreviewSize;
_textureView.LayoutParameters =
new FrameLayout.LayoutParams(h, w, GravityFlags.Center);
try
{
_camera.SetPreviewTexture(surface);
_camera.StartPreview();
}
catch (Java.IO.IOException ex)
{
Console.WriteLine(ex.Message);
}
_textureView.Rotation = 90.0f;
}
在firts行中,获取“相机参数”,然后选择“ firts”([0]),然后获得“支持的图片大小”,最后设置“ Picture Size”,
Android.Hardware.Camera.Parameters param = _camera.GetParameters();
IList<Android.Hardware.Camera.Size> supportedSizes = param.SupportedPictureSizes;
Android.Hardware.Camera.Size sizePicture = supportedSizes[0];
param.SetPictureSize(sizePicture.Height, sizePicture.Width);
_camera.SetParameters(param);
但是,当我运行代码时,会显示以下消息:
Unhandled Exception:
Java.Lang.RuntimeException: setParameters failed
这是怎么了?我无法设置该函数返回的任何受支持的大小?我该如何选择其中任何一个?还有其他我要考虑的东西吗?
解决方法:
您已转置了width和height参数,从而提供了无效的(不受支持的)图片尺寸.
param.SetPictureSize(sizePicture.Width, sizePicture.Height);
void setPictureSize (int width, int height)
回复:https://developer.android.com/reference/android/hardware/Camera.Parameters.html