Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xamarin.forms 在厨房和照相机上以塔玛林的形式拍照_Xamarin.forms - Fatal编程技术网

Xamarin.forms 在厨房和照相机上以塔玛林的形式拍照

Xamarin.forms 在厨房和照相机上以塔玛林的形式拍照,xamarin.forms,Xamarin.forms,我使用了以下代码,但它不起作用 using System; using System.Threading.Tasks; using Xamarin.Forms; using XLabs.Platform.Device; using XLabs.Platform.Services.Media; namespace CalbrenEnterprises.Pages { public class TestPage : ContentPage { private I

我使用了以下代码,但它不起作用

using System;
using System.Threading.Tasks;

using Xamarin.Forms;

using XLabs.Platform.Device;
using XLabs.Platform.Services.Media;

namespace CalbrenEnterprises.Pages
{
    public class TestPage : ContentPage
    {
        private ImageSource imageSource;
        private IMediaPicker mediaPicker;
        private Image img;
        private string status;

        public TestPage()
        {
            this.Title = "Camera Test";


            NavigationPage.SetHasNavigationBar(this, false);


            img = new Image() { HeightRequest = 300, WidthRequest = 300, BackgroundColor = Color.FromHex("#D6D6D2"), Aspect = Aspect.AspectFit };


            var addPictureButton = new Button()
            {
                Text = "Select Picture",
                Command = new Command(async () => { await SelectPicture(); })
            };


            StackLayout stack = new StackLayout();
            stack.VerticalOptions = LayoutOptions.FillAndExpand;

            stack.Children.Add(new BoxView { Color = Color.Transparent, HeightRequest = 20 });
            stack.Children.Add(addPictureButton);
            stack.Children.Add(img);


            ScrollView scrollview = new ScrollView
            {
                Orientation = ScrollOrientation.Vertical,
                VerticalOptions = LayoutOptions.FillAndExpand,
                Content = stack

            };

            this.Content = new StackLayout
            {
                Children = { scrollview }
            };


        }


        private async Task SelectPicture()
        {

            mediaPicker = DependencyService.Get<IMediaPicker>();

            imageSource = null;

            try
            {
                var mediaFile = await mediaPicker.SelectPhotoAsync(new CameraMediaStorageOptions
                {
                    DefaultCamera = CameraDevice.Front,
                    MaxPixelDimension = 400
                });
                imageSource = ImageSource.FromStream(() => mediaFile.Source);
                img.Source = imageSource;
            }
            catch (System.Exception ex)
            {
                this.status = ex.Message;
            }
        }



    }
}
问题:

如何在Xamarin.forms中的PCL项目中从gallery中选择照片并从照相机中拍照?

var device=Resolver.Resolve; mediaPicker=DependencyService.Get??device.MediaPicker; 如果mediaPicker==null,则抛出新的NullReferenceExceptionMediaPicker DependencyService.Get错误; 尝试 { 如果mediaPicker.isCamera可用 { var options=新的摄影师摄影选项{ DefaultCamera=CameraDevice.Front, SaveMediaOnCapture=true, Directory=YourAppName, Name=string.FormatYourAppName_u{0},DateTime.Now.tostringymmddhhmmss, MaxPixelDimension=1024, 质量百分比=85 }; var mediaFile=wait mediaPicker.takephotoasynchoptions; 如果mediaFile!=null&&mediaFile.Source!=null { //用你的照片做点什么 } } 其他的 { Logger.InfoCamera不可用; } } 捕获任务取消异常 { Logger.InfoTakePhoto被取消; } 捕获异常 { Logger.Errorex; }
也许,您应该发布什么不起作用,如果存在,还应该发布错误消息,以便有人可以帮助您:-嗨..我正在尝试使用SelectPhoto方法var selectedPhoto=wait mediaPicker.selectphotoasynchoptions;它并没有重新运行任何东西