It's easy to set a source for an image in Xamarin:
using Xamarin.Forms;
Image image = new Image;
image.Source = "someImage.jpg";
But I can not do the reverse operation.
ex: given an image with its source already set, print the source.
Console.WriteLine ("Print Image source ==> {0}",image.Source);
Console.WriteLine ("Print Image source ==> {0}",image.Source.ToString());
... and a few more incoherent combinations.
Could anyone tell me how to get the source (with a string) from an image.
The Xamarin.Forms Image.Source property is of type ImageSource.
ImageSource in Xamarin.Forms has a few classes that inherit this class such as:-
You can type check the Image.Source to see what implementation is being used in Image.Source, and then cast it, and access the properties of the casted object.
For instance (assuming ImageSource is a FileImageSource) you will have something like:-
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;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句