WPF - Cannot access static resource image [duplicate]











up vote
0
down vote

favorite













This question already has an answer here:




  • WPF - Import image as resource

    3 answers



  • How do I change an image source dynamically from code-behind in WPF with an image in Properties.Resources?

    1 answer




I have done quite a bit of research but still cannot figure this out.



I have made a program that I would like to include a jpg image as an embedded resource, in the exe file. The reason is I don't want anyone tampering or changing the image once the program is released, and also when I distribute the program it would be good if there was only one file to send.



This is what I have at the moment, which works fine when loading an image on the hard drive.



<Border.Resources>
<BitmapImage x:Key="Logo" UriSource="C:UsersgmccoPicturesDevelopmentLogo.jpg"/>
</Border.Resources>
<Grid>
<Image Source="{StaticResource Logo}"/>
</Grid>


I have loaded the image into the program and changed the properties to make it an embedded resource, but cannot seem to use it.



How do you reference a embedded image in XAML please?



Snapshot










share|improve this question















marked as duplicate by Clemens wpf
Users with the  wpf badge can single-handedly close wpf questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
yesterday


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











  • 2




    You could have searched StackOverflow for "wpf image resource". In short, the Build Action should be Resource (for an assembly resource), and the image should be loaded in XAML by a path like /Images/Logo.jpg, where the image file is located in a project folder named "Images".
    – Clemens
    yesterday












  • I still cannot get this working. I have the image in the resources folder and I have set the Build Action to Resource. If I reference the path as /Images/Logo.jpg then I get an error, could not find a part of the path C:ImagesLogo.jpg. If I reference it to where it actually is then it loads fine.but after I build the program and delete the image, the program does not load. Put the image back and the program loads again.
    – Grant McConville
    yesterday












  • If the image file is in a folder named "Resources", the path should obviously be /Resources/Logo.jpg.
    – Clemens
    yesterday












  • Added a snapshot. See what I mean?
    – Grant McConville
    yesterday










  • You mean a screenshot. And you should write Resources instead of Resource, if the image is in a folder named Resources.
    – Clemens
    yesterday

















up vote
0
down vote

favorite













This question already has an answer here:




  • WPF - Import image as resource

    3 answers



  • How do I change an image source dynamically from code-behind in WPF with an image in Properties.Resources?

    1 answer




I have done quite a bit of research but still cannot figure this out.



I have made a program that I would like to include a jpg image as an embedded resource, in the exe file. The reason is I don't want anyone tampering or changing the image once the program is released, and also when I distribute the program it would be good if there was only one file to send.



This is what I have at the moment, which works fine when loading an image on the hard drive.



<Border.Resources>
<BitmapImage x:Key="Logo" UriSource="C:UsersgmccoPicturesDevelopmentLogo.jpg"/>
</Border.Resources>
<Grid>
<Image Source="{StaticResource Logo}"/>
</Grid>


I have loaded the image into the program and changed the properties to make it an embedded resource, but cannot seem to use it.



How do you reference a embedded image in XAML please?



Snapshot










share|improve this question















marked as duplicate by Clemens wpf
Users with the  wpf badge can single-handedly close wpf questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
yesterday


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











  • 2




    You could have searched StackOverflow for "wpf image resource". In short, the Build Action should be Resource (for an assembly resource), and the image should be loaded in XAML by a path like /Images/Logo.jpg, where the image file is located in a project folder named "Images".
    – Clemens
    yesterday












  • I still cannot get this working. I have the image in the resources folder and I have set the Build Action to Resource. If I reference the path as /Images/Logo.jpg then I get an error, could not find a part of the path C:ImagesLogo.jpg. If I reference it to where it actually is then it loads fine.but after I build the program and delete the image, the program does not load. Put the image back and the program loads again.
    – Grant McConville
    yesterday












  • If the image file is in a folder named "Resources", the path should obviously be /Resources/Logo.jpg.
    – Clemens
    yesterday












  • Added a snapshot. See what I mean?
    – Grant McConville
    yesterday










  • You mean a screenshot. And you should write Resources instead of Resource, if the image is in a folder named Resources.
    – Clemens
    yesterday















up vote
0
down vote

favorite









up vote
0
down vote

favorite












This question already has an answer here:




  • WPF - Import image as resource

    3 answers



  • How do I change an image source dynamically from code-behind in WPF with an image in Properties.Resources?

    1 answer




I have done quite a bit of research but still cannot figure this out.



I have made a program that I would like to include a jpg image as an embedded resource, in the exe file. The reason is I don't want anyone tampering or changing the image once the program is released, and also when I distribute the program it would be good if there was only one file to send.



This is what I have at the moment, which works fine when loading an image on the hard drive.



<Border.Resources>
<BitmapImage x:Key="Logo" UriSource="C:UsersgmccoPicturesDevelopmentLogo.jpg"/>
</Border.Resources>
<Grid>
<Image Source="{StaticResource Logo}"/>
</Grid>


I have loaded the image into the program and changed the properties to make it an embedded resource, but cannot seem to use it.



How do you reference a embedded image in XAML please?



Snapshot










share|improve this question
















This question already has an answer here:




  • WPF - Import image as resource

    3 answers



  • How do I change an image source dynamically from code-behind in WPF with an image in Properties.Resources?

    1 answer




I have done quite a bit of research but still cannot figure this out.



I have made a program that I would like to include a jpg image as an embedded resource, in the exe file. The reason is I don't want anyone tampering or changing the image once the program is released, and also when I distribute the program it would be good if there was only one file to send.



This is what I have at the moment, which works fine when loading an image on the hard drive.



<Border.Resources>
<BitmapImage x:Key="Logo" UriSource="C:UsersgmccoPicturesDevelopmentLogo.jpg"/>
</Border.Resources>
<Grid>
<Image Source="{StaticResource Logo}"/>
</Grid>


I have loaded the image into the program and changed the properties to make it an embedded resource, but cannot seem to use it.



How do you reference a embedded image in XAML please?



Snapshot





This question already has an answer here:




  • WPF - Import image as resource

    3 answers



  • How do I change an image source dynamically from code-behind in WPF with an image in Properties.Resources?

    1 answer








wpf image xaml resources






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday

























asked yesterday









Grant McConville

94




94




marked as duplicate by Clemens wpf
Users with the  wpf badge can single-handedly close wpf questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
yesterday


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Clemens wpf
Users with the  wpf badge can single-handedly close wpf questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
yesterday


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 2




    You could have searched StackOverflow for "wpf image resource". In short, the Build Action should be Resource (for an assembly resource), and the image should be loaded in XAML by a path like /Images/Logo.jpg, where the image file is located in a project folder named "Images".
    – Clemens
    yesterday












  • I still cannot get this working. I have the image in the resources folder and I have set the Build Action to Resource. If I reference the path as /Images/Logo.jpg then I get an error, could not find a part of the path C:ImagesLogo.jpg. If I reference it to where it actually is then it loads fine.but after I build the program and delete the image, the program does not load. Put the image back and the program loads again.
    – Grant McConville
    yesterday












  • If the image file is in a folder named "Resources", the path should obviously be /Resources/Logo.jpg.
    – Clemens
    yesterday












  • Added a snapshot. See what I mean?
    – Grant McConville
    yesterday










  • You mean a screenshot. And you should write Resources instead of Resource, if the image is in a folder named Resources.
    – Clemens
    yesterday
















  • 2




    You could have searched StackOverflow for "wpf image resource". In short, the Build Action should be Resource (for an assembly resource), and the image should be loaded in XAML by a path like /Images/Logo.jpg, where the image file is located in a project folder named "Images".
    – Clemens
    yesterday












  • I still cannot get this working. I have the image in the resources folder and I have set the Build Action to Resource. If I reference the path as /Images/Logo.jpg then I get an error, could not find a part of the path C:ImagesLogo.jpg. If I reference it to where it actually is then it loads fine.but after I build the program and delete the image, the program does not load. Put the image back and the program loads again.
    – Grant McConville
    yesterday












  • If the image file is in a folder named "Resources", the path should obviously be /Resources/Logo.jpg.
    – Clemens
    yesterday












  • Added a snapshot. See what I mean?
    – Grant McConville
    yesterday










  • You mean a screenshot. And you should write Resources instead of Resource, if the image is in a folder named Resources.
    – Clemens
    yesterday










2




2




You could have searched StackOverflow for "wpf image resource". In short, the Build Action should be Resource (for an assembly resource), and the image should be loaded in XAML by a path like /Images/Logo.jpg, where the image file is located in a project folder named "Images".
– Clemens
yesterday






You could have searched StackOverflow for "wpf image resource". In short, the Build Action should be Resource (for an assembly resource), and the image should be loaded in XAML by a path like /Images/Logo.jpg, where the image file is located in a project folder named "Images".
– Clemens
yesterday














I still cannot get this working. I have the image in the resources folder and I have set the Build Action to Resource. If I reference the path as /Images/Logo.jpg then I get an error, could not find a part of the path C:ImagesLogo.jpg. If I reference it to where it actually is then it loads fine.but after I build the program and delete the image, the program does not load. Put the image back and the program loads again.
– Grant McConville
yesterday






I still cannot get this working. I have the image in the resources folder and I have set the Build Action to Resource. If I reference the path as /Images/Logo.jpg then I get an error, could not find a part of the path C:ImagesLogo.jpg. If I reference it to where it actually is then it loads fine.but after I build the program and delete the image, the program does not load. Put the image back and the program loads again.
– Grant McConville
yesterday














If the image file is in a folder named "Resources", the path should obviously be /Resources/Logo.jpg.
– Clemens
yesterday






If the image file is in a folder named "Resources", the path should obviously be /Resources/Logo.jpg.
– Clemens
yesterday














Added a snapshot. See what I mean?
– Grant McConville
yesterday




Added a snapshot. See what I mean?
– Grant McConville
yesterday












You mean a screenshot. And you should write Resources instead of Resource, if the image is in a folder named Resources.
– Clemens
yesterday






You mean a screenshot. And you should write Resources instead of Resource, if the image is in a folder named Resources.
– Clemens
yesterday



















active

oldest

votes






















active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

TypeError: fit_transform() missing 1 required positional argument: 'X'