ThinkGeo.com    |     Blog    |     Wiki    |     Support

BitmapImage does not work with relative path image file

Hi,

When I use relative path for image, the image does not show.

Marker marker = new Marker(new PointShape(projection.ConvertToInternalProjection(place.Location.Geoposition.Longitude, place.Location.Geoposition.Latitude)));

marker.ImageSource = new BitmapImage(new Uri(“Assets/AQUABLANK.png”, UriKind.Relative));

I have to use absolute path for AQUABLANK.png.

Yes, I made sure that AQUABLANK.png property set to “Copy if newer”.

Please take a look. Thanks,

Liang

Hi Liang,

This post is under Desktop category, but the folder looks like Mobile version. Could you please let us know which version you are using?

If that’s for Android, I found some topics from internet it mentioned relative path is not good solution for Android, I think you should want to reference the sample code about path MainActivity.cs (3.8 KB) :

I hope that’s helpful.

Regards,

Ethan

Hi Ethan,

I am using Desktop .net core 3.1 WPF.

Thanks,

Liang

Hi Liang,

Thanks for your information, I had reproduced that.

I am not sure whether it’s a bug, I will double check with our developer team.

Any update I will let you know.

Regards,

Ethan

Hi Liang,

Our developer research it and found it’s not caused by our code, here is two solutions about it:

  1. Choose relative path:

    marker.ImageSource = new BitmapImage(new Uri(@"/WpfApplication1;component/Assets/AQUABLANK.png", UriKind.Relative));     
    

It point to the image which is called “AQUABLANK.png” in a folder called “Assets” with its “Build Action” set to “Resource” in an assembly called “WpfApplication1”.

You can found more information here: https://docs.microsoft.com/en-us/dotnet/framework/wpf/app-development/pack-uris-in-wpf?redirectedfrom=MSDN

  1. Choose absolute path, but you get it from .net API, it still looks like relative path in your code.

         marker.ImageSource = new BitmapImage(new Uri(Path.GetFullPath("Assets/AQUABLANK.png"), UriKind.Absolute));
    

It point to the image which is called “AQUABLANK.png” in a folder called “Assets” with its “Build Action” set to “None” and “Copy to Output Directory” set to “Copy if newer” or “Copy always”.

I tested both of them in .net core version and they work well.

I hope that’s helpful to solve your problem.

Regards,

Ethan