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

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

Susan Sarandon
Release: 2025-01-18 23:32:12
Original
947 people have browsed it

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

Assigning BitmapImage from Resources.resx to Image.Source

In this inquiry, the user seeks assistance in assigning a BitmapImage from Resources.resx to an Image.Source. The user has encountered an issue when attempting to use Pack URIs within their code.

To resolve this issue, it's crucial to ensure that the image file is located within a folder named "Resources" in the Visual Studio project. Additionally, its Build Action must be set to Resource. This Resources folder is different from Resources.resx and can be renamed as desired.

By implementing these steps, the Pack URI will function correctly, and the application will be able to access the image from different machines even if the absolute path may differ.

Here's a revised code example:

logoImage.Source = new BitmapImage(new Uri(@"pack://application:,,,/Resources/logo.png"));
Copy after login

The above is the detailed content of How to 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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template