【发布时间】:2016-07-22 08:40:49
【问题描述】:
我正在尝试解决 uri 地址转换为图像的问题。主要思想,我在做什么我想从画廊中挑选图像,绑定它并将其保存到数据库。一切正常,我可以将字符串图像路径保存到类属性,但不幸的是,我无法将该地址转换为我将在其中显示图像的 imageSource,因为现在我看到了空的图像圈。
这是我从图库中选择图片并尝试转换为图片的地方:
IGalleryImageService galleryService = Xamarin.Forms.DependencyService.Get<IGalleryImageService>();
galleryService.ImageSelected += (o, imageSourceEventArgs) =>
{
Uri uri = new Uri(imageSourceEventArgs.ImageSource);
(ActivePage.Page as PageTemplate).CarImage.Source = ImageSource.FromFile(uri.ToString());
ActivePage.CarImageBindable = (ActivePage.Page as PageTemplate).CarImage.Source.GetValue(StreamImageSource.StreamProperty).ToString(); // here I am trying to convert from path address to image
};
galleryService.SelectImage();
这是我的页面模板
public partial class PageTemplate: ContentPage
{
public CircleImage CarImage
{
get
{
return Car;
}
set
{
Car = value;
}
}
}
和我正在显示图像的 PageTemplate.xaml。
<controls:CircleImage x:Name="Car" AbsoluteLayout.LayoutBounds=".5,0,-1,-1" AbsoluteLayout.LayoutFlags="PositionProportional" Aspect="AspectFill">
</controls:CircleImage>
这是我在 Unit2 类中的可绑定属性:
public string CarImageBindable
{
get
{
return base.CarImage;
}
set
{
base.CarImage = value;
OnPropertyChanged(nameof(CarImageBindable));
}
}
Core 项目单元类的另一个属性:
public int Id { get; set; }
public DateTime StartDate { get; set; }
public string CarImage { get; set; }
这就是为什么我决定将所有属性都设为字符串数据类型,因为我想保存图像路径。是的,然后再次从数据库转换为物理图像。
感谢您的回答或建议。
【问题讨论】:
-
您好,在您的代码中有一行 (ActivePage.Page as PageTemplate).CarImage.Source = ImageSource.FromFile(uri.ToString());为什么不只是 (ActivePage.Page as PageTemplate).CarImage.Source = uri;
标签: c# sqlite binding uri xamarin.forms