1
有誰在Xamarin.Forms.Labs'攝像功能的Xamarin.Forms的例子嗎?Xamarin形式 - Xamarin上頁構成實驗室相機顯示出來
我試圖讓它工作,但它似乎並沒有工作。
這裏是我的代碼:
public partial class CameraPictureInfoPage : ContentPage
{
public CameraPictureInfoPage()
{
Image img = new Image();
this.Appearing += async (s, e) => {
img.Source = await GetPicture (true);
};
this.Content = new StackLayout {
Orientation = StackOrientation.Vertical,
VerticalOptions = LayoutOptions.Center,
WidthRequest = 250,
Padding = 40, Spacing = 10,
Children = {
img
}
};
}
async Task<ImageSource> GetPicture(bool chooseNotTake){
var mediaPicker = DependencyService.Get<IMediaPicker>();
ImageSource imgSource = null;
if (mediaPicker != null) {
Task<MediaFile> pick;
if (chooseNotTake) {
pick = mediaPicker.TakePhotoAsync (new CameraMediaStorageOptions {
DefaultCamera = CameraDevice.Rear,
MaxPixelDimension = 1024,
});
} else {
pick = mediaPicker.SelectPhotoAsync (new CameraMediaStorageOptions{ MaxPixelDimension = 1024 });
}
await pick.ContinueWith (t => {
if (!t.IsFaulted && !t.IsCanceled) {
var mediaFile = t.Result;
MemoryStream mstr = new MemoryStream();
mediaFile.Source.CopyTo (mstr);
imgSource = ImageSource.FromStream (() => mstr);
}
return imgSource;
});
}
return imgSource;
}
}
它仍然不起作用,iamge沒有出現,我得到的唯一一個操作可以一次處於活動狀態。 我的代碼在你的電腦上工作嗎? – user3841879
修改後的代碼適用於我的電腦,不調用GetPicture() –
的版本可以發佈您的整個代碼plz嗎? – user3841879