加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 如何将Image.Source作为字符串

发布时间:2020-12-15 18:34:00 所属栏目:百科 来源:网络整理
导读: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.
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;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读