Home > Backend Development > C++ > How to Correctly Assign a BitmapImage from Resources.resx to Image.Source?

How to Correctly Assign a BitmapImage from Resources.resx to Image.Source?

DDD
Release: 2025-01-18 23:47:10
Original
944 people have browsed it

How to Correctly Assign a BitmapImage from Resources.resx to Image.Source?

Solve the problem of loading BitmapImage from Resources.resx resource file to Image.Source

Your attempt to assign the BitmapImage in Resources.resx to Image.Source failed because the Pack URI path is incorrect.

To use relative paths in Pack URIs, the logo.png file must be located in a folder named "Resources" in the Visual Studio project, and its build action must be set to "Resources". This "Resources" folder has nothing to do with Resources.resx and can be renamed at will.

So your code should look like this:

<code class="language-csharp">logoImage.Source = new BitmapImage(new Uri(@"pack://application:,,,/Resources/logo.png"));</code>
Copy after login

The above is the detailed content of How to Correctly Assign a BitmapImage from Resources.resx to Image.Source?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template