【发布时间】:2017-10-17 16:06:13
【问题描述】:
我正在尝试使用 Xamarin 在 Android 上构建相机应用。我想要做的是当用户点击“拍照”按钮时,相机会自动将后置摄像头切换到前置摄像头并捕捉图像,这意味着“拍照 strong>" 按钮将做两件事:同时切换相机和捕获图像。
我是 Xamarin 的新手,正在开发 Android 应用程序。我搜索了很多教程来构建相机应用程序,但它们似乎很简单,当用户点击“take image”按钮时,我没有看到任何覆盖功能。这是我在主要活动中的代码(只是为了构建简单的相机应用程序):
ImageView imageView;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
var btnCamera = FindViewById<Button>(Resource.Id.btnCamera);
imageView = FindViewById<ImageView>(Resource.Id.imageView);
btnCamera.Click += BtnCamera_Click;
}
protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
Bitmap bitmap = (Bitmap)data.Extras.Get("data");
imageView.SetImageBitmap(bitmap);
}
// When user tap on the button, open camra app
private void BtnCamera_Click(object sender, System.EventArgs e)
{
Intent intent = new Intent(MediaStore.ActionImageCapture);
StartActivityForResult(intent, 0);
}
任何想法都会有所帮助,非常感谢。
【问题讨论】:
标签: android xamarin.android android-camera