It’s easy to set a source for an image in Xamarin:
using Xamarin.Forms; Image image = new Image; image.Source = "someImage.jpg";
但我不能做相反的操作.
例如:给定已设置其源的图像,打印源.
Console.WriteLine ("Print Image source ==> {0}",image.Source); Console.WriteLine ("Print Image source ==> {0}",image.Source.ToString());
…
还有一些不连贯的组合.
谁能告诉我如何从图像中获取源(带字符串).
解决方法
Xamarin.Forms Image.Source属性的类型为ImageSource.
Xamarin.Forms中的ImageSource有一些继承此类的类,如: –
> FileImageSource
> StreamImageSource
> UriImageSource
您可以键入检查Image.Source以查看Image.Source中正在使用的实现,然后转换它,并访问已转换对象的属性.
例如(假设ImageSource是FileImageSource),您将拥有如下内容: –
Xamarin.Forms.Image objImage; .. .. .. if (objImage.Source is Xamarin.Forms.FileImageSource) { Xamarin.Forms.FileImageSource objFileImageSource = (Xamarin.Forms.FileImageSource)objImage.Source; // // Access the file that was specified:- string strFileName = objFileImageSource.File; }