【问题标题】:Xamarin Forms MVVM (Prism) with Media.Plugin - How to get a taken picture from device CameraXamarin Forms MVVM (Prism) with Media.Plugin - 如何从设备相机获取照片
【发布时间】:2020-03-09 07:14:14
【问题描述】:
How to take a picture by the camera and show in display before saving data.....

在页面上..

    <Image Source="{Binding ImageTakeFile2.source}" Grid.Column="0" WidthRequest="100" HeightRequest="100" HorizontalOptions="Start"/>

在 ViewModel..

private MediaFile _photo;
 _photo = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions
        { Directory = "Sample", Name = "test.jpg", PhotoSize = PhotoSize.MaxWidthHeight, MaxWidthHeight = imageSize });


ImageTakeFile2.Source = ImageSource.FromStream(() =>
     {
         var stream = _photo.GetStream();
         return stream;
     });

【问题讨论】:

  • 我不确定你的问题是什么!
  • 先生,我想添加一个带有相机照片的新员工资料,并在保存到数据库之前显示在图像视图中......我只有在图像框中显示图像时出现问题。
  • 那么如何在 ViewModel 中拥有 Image 实例
  • 我有 ImageTakeFile2 图像类型。 ImageTakeFile2.soure 要显示在图像框中
  • 好吧,我不确定ImageTakeFile2 对象的类型是什么,但无论如何属性Source 和绑定source 会因为大小写不同而不同,所以绑定应该看起来像@987654327 @

标签: xamarin.forms xamarin.android


【解决方案1】:

用途:

ImageTakeFile2.Source = ImageSource.FromFile(_photo.Path);

.Source 必须声明为 ImageSource

【讨论】:

    【解决方案2】:

    解决了!...

    <Image Source="{Binding Img}"/> 
    

    在视图模型中...

      public ImageSource Img 
        {
            get { return _img; }
            set { _img = value;
                OnPropertyChanged("Img");
            }
        }  
      private MediaFile _photo; { get; set; }                                
      Img = ImageSource.FromFile(_photo.Path);
    

    【讨论】:

    • 没关系。取决于您的视图模型。
    猜你喜欢
    • 2018-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-18
    • 2019-08-14
    • 2011-11-26
    • 2019-07-30
    • 2018-04-25
    相关资源
    最近更新 更多