![](/img/trans.png)
[英]How to take a picture with iOS camera and save the image to camera roll using Xamarin
[英]How to take a picture in Xamarin?
我正在嘗試使用Android.Hardware中的Camera類拍照。 我正在獲取提要,並且相機正在自動對焦。 問題是我不知道如何拍照。
_camera = Camera.Open();
Camera.Parameters param = _camera.GetParameters();
param.FocusMode = Camera.Parameters.FocusModeContinuousPicture;
_camera.SetParameters(param);
var previewSize = _camera.GetParameters().PreviewSize;
_textureView.LayoutParameters =
new FrameLayout.LayoutParams(previewSize.Width,
previewSize.Height, GravityFlags.Center);
try
{
_camera.SetPreviewTexture(surface);
_camera.StartPreview();
}
catch (Java.IO.IOException ex)
{
System.Console.WriteLine(ex.Message);
}
// this is the sort of thing TextureView enables
_textureView.Rotation = 90.0f;
但是您可以使用此代碼來拍照(TakeAPicture)。
private void TakeAPicture (object sender, EventArgs eventArgs)
{
Intent intent = new Intent (MediaStore.ActionImageCapture);
App._file = new File (App._dir, String.Format("myPhoto_{0}.jpg", Guid.NewGuid()));
intent.PutExtra (MediaStore.ExtraOutput, Uri.FromFile (App._file));
StartActivityForResult (intent, 0);
}
編碼愉快! :)
TakePicture方法是您要尋找的方法。 要使用此功能,您需要實現一些接口。 特別是IPictureCallback在OnPictureTaken中接收圖片。
一個示例實現如下所示:
public void OnPictureTaken(byte[] data, Android.Hardware.Camera camera)
{
camera.StopPreview();
Toast.MakeText(this, "Cheese", ToastLength.Short).Show();
camera.StartPreview();
}
為防止該應用程序掛起,您需要停止預覽並重新(重新)啟動它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.