question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Loading Bitmap using Relative File Path

See original GitHub issue

Before #2104, it is able to use the relative path for Image

<Image Width="16" Height="16" Source="Images/File.png" />

(mak sure Directory.SetCurrentDirectory(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)); first)

, where File.png is a Content that will copy to output directory. Currently, It throws a error of :

System.ArgumentException: Relative uris for 'resm' scheme aren't supported; resm:SampleApp.MainWindow.xaml?assembly=SampleApp uses resm.

However, it still is able to load the image with relative path by

Bitmap image = new Bitmap("Images/File.png");

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

5reactions
kekekekscommented, Dec 18, 2018

We might add Host handling for file: scheme. So app-relative paths would look like file://appdir/Images/File.png. I think hostname in file:// is never used, so it should be fine.

3reactions
nicolasr75commented, Jan 25, 2019

Ok, I ended up with a mix of property and static resource binding. As a reference, here is my working demo code. Thanks again for the quick help!

xmlns:clr="clr-namespace:System;assembly=mscorlib"
xmlns:local="clr-namespace:MyNamespace"
...
<Window.Resources>
	<clr:String x:Key="logoPath">Graphics/StaticLogo.png</clr:String>
	<local:PathToBitmapConverter x:Key="pathToBitmapConverter"/>
</Window.Resources>
...
<Image Source="{Binding Source={StaticResource logoPath}, Converter={StaticResource pathToBitmapConverter}}"></Image>
<Image Source="{Binding DynamicImage, Converter={StaticResource pathToBitmapConverter}}"></Image>

And the converter class

public class PathToBitmapConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        string path = (string)value;

        return new Bitmap(path);
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Relative Path when creating Bitmap
I am trying to create a Bitmap using: bitmap = new Bitmap(@"Movies\View\Images\missing_person.bmp");. However, I am receiving a System.
Read more >
wxBitmap load from file relative path
Hello, i'm new to wxWidgets and to the forum! I have a very simple question... when I load a bitmap from a file...
Read more >
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.
Read more >
C# Bitmap only loads when static file address is specified
Start by doing two things. First, change your code slightly: C#. string fileSpec = string.Format(@".\Images\{0}\{1}.png", subfolderName, ...
Read more >
Bitmaps — wxGlade 1.0.0 documentation
Specify the absolute or relative path to the bitmap file. For an absolute path, you may use the file dialog by clicking the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found