1

I have a collection with a few images, but now I need to find the right ResourceId by the correct Image. How can I do that, because I couldn't find it on internet?

Here is the code where it should be placed:

var image = (Image)e.NewItems[e.NewItems.Count - 1];
string resourceID = ....

Any suggestions?

A. Vreeswijk
  • 822
  • 1
  • 19
  • 57

2 Answers2

1

It's not possible as far as I know, to get or set the resource id like so

Assuming you are using a list of Image objects in NewItems.

Maybe you get it if you know the Image name like here

What are you trying to achieve here? add more information to clarify a bit more

PS: answering cause I can't comment yet

UPDATED :

Check the "Loading a Bitmap Resource" section in the docs here

Leo Jebran
  • 154
  • 8
  • I want to draw the bitmap in skiasharp, but I need the ResourceId for that – A. Vreeswijk Nov 25 '19 at 13:13
  • Check the "Loading a Bitmap Resource" section in the docs here: https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/graphics/skiasharp/basics/bitmaps – Leo Jebran Nov 25 '19 at 13:19
  • My stream is null? – A. Vreeswijk Nov 25 '19 at 15:22
  • should be because of the source ID string resourceID = "SkiaSharpFormsDemos.Media.monkey.png"; must be set to where you saved your bit map I see you accepted this answer, thx and I hope you have solved it – Leo Jebran Nov 26 '19 at 08:12
0

Create a custom image file ,which inherits Image and Add unique Id into it.

public class CustomImage: Image{
    public int UniqueId {get;set;} = CreateUniqueID(); //Add some logic to create unique id;
}

Now,you can use this CustomImage anywhere with unique Id.

you can access it by: CustomImage.UniqueId

bhavya joshi
  • 1,096
  • 10
  • 20