How to get Image.Source as string

Loebre

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.

Pete

The Xamarin.Forms Image.Source property is of type ImageSource.

ImageSource in Xamarin.Forms has a few classes that inherit this class such as:-

  • FileImageSource
  • StreamImageSource
  • UriImageSource

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] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

UWP:在'get;中从FilePath设置image.source;& 放;'

来自分类Dev

How to get type from String?

来自分类Dev

How to get the source of a javascript bookmark from itself when running?

来自分类Dev

How to get length of a string using strlen function

来自分类Dev

How to get string for current namespace in Macro

来自分类Dev

How do you get the file size of an image on the web page with Javascript?

来自分类Dev

get_rollit_source的问题

来自分类Dev

ObjectDisposedException when I try to use an Image source

来自分类Dev

ImageButton: Mipmap source image not stretching to fill button

来自分类Dev

未显示位图的Image.Source

来自分类Dev

<Image source = {require(“”)} />不能正确显示?

来自分类Dev

<Image source = {require(“”)} />不能正确显示?

来自分类Dev

<Image source = {require(“”)} />不能正确显示?

来自分类Dev

<Image source = {require(“”)} />不能正确显示?

来自分类Dev

动画,Image.Source和绑定

来自分类Dev

将 BitmapImage 转换为 Image.Source

来自分类Dev

WPF Image.Source 什么都不做

来自分类Dev

当 Image.Source 为空时不渲染 Image

来自分类Dev

How to get 8 random unique elements from a string array?

来自分类Dev

How to randomly get a string from a collection but prefer strings at the beginning of the collection

来自分类Dev

How to get the parameter from a relative URL string in C#?

来自分类Dev

How to get the OS Version String in MAC 10.10 without using gestalt

来自分类Dev

how to get array key from string array in java

来自分类Dev

How do I get the length of the first line in a multi line string?

来自分类Dev

gdk_device_get_source!= GDK_SOURCE_KEYBOARD

来自分类Dev

gdk_device_get_source!= GDK_SOURCE_KEYBOARD

来自分类Dev

How to get and display image as byte array from database on Windows Phone 8.1

来自分类Dev

How to execute java source in Eclipse

来自分类Dev

Use base64 svg image as css content source

Related 相关文章

  1. 1

    UWP:在'get;中从FilePath设置image.source;& 放;'

  2. 2

    How to get type from String?

  3. 3

    How to get the source of a javascript bookmark from itself when running?

  4. 4

    How to get length of a string using strlen function

  5. 5

    How to get string for current namespace in Macro

  6. 6

    How do you get the file size of an image on the web page with Javascript?

  7. 7

    get_rollit_source的问题

  8. 8

    ObjectDisposedException when I try to use an Image source

  9. 9

    ImageButton: Mipmap source image not stretching to fill button

  10. 10

    未显示位图的Image.Source

  11. 11

    <Image source = {require(“”)} />不能正确显示?

  12. 12

    <Image source = {require(“”)} />不能正确显示?

  13. 13

    <Image source = {require(“”)} />不能正确显示?

  14. 14

    <Image source = {require(“”)} />不能正确显示?

  15. 15

    动画,Image.Source和绑定

  16. 16

    将 BitmapImage 转换为 Image.Source

  17. 17

    WPF Image.Source 什么都不做

  18. 18

    当 Image.Source 为空时不渲染 Image

  19. 19

    How to get 8 random unique elements from a string array?

  20. 20

    How to randomly get a string from a collection but prefer strings at the beginning of the collection

  21. 21

    How to get the parameter from a relative URL string in C#?

  22. 22

    How to get the OS Version String in MAC 10.10 without using gestalt

  23. 23

    how to get array key from string array in java

  24. 24

    How do I get the length of the first line in a multi line string?

  25. 25

    gdk_device_get_source!= GDK_SOURCE_KEYBOARD

  26. 26

    gdk_device_get_source!= GDK_SOURCE_KEYBOARD

  27. 27

    How to get and display image as byte array from database on Windows Phone 8.1

  28. 28

    How to execute java source in Eclipse

  29. 29

    Use base64 svg image as css content source

热门标签

归档