---
title: "Adding Image in Run Time"  
description: "Adding Image in Run Time"  
author: "Anonymous User"  
published: 2013-09-23  
updated: 2013-09-23  
canonical: https://www.mindstick.com/forum/1503/adding-image-in-run-time  
category: "wpf"  
tags: ["wpf", "Adding Image in Run Time", "run time", "add image run time in c#", "mindstick"]  
reading_time: 1 minute  

---

# Adding Image in Run Time

I want to [add an image](https://www.mindstick.com/forum/33784/how-to-add-an-image-on-uitableview-cell-in-ios) from my [Resources](https://yourviews.mindstick.com/view/293/renovation-causes-wastage-of-resources) to an Image on the press of a [Button](https://www.mindstick.com/articles/63/how-to-add-button-in-datagridview-in-csharp-dot-net).

Using Image1.Source = Properties.Resources.MyImage Does not work because the Image1 is of type ImageSource and the [Left](https://www.mindstick.com/articles/12768/don-t-be-left-behind-with-the-new-it-revolution) side is of type Drawing. How can I [fix](https://yourviews.mindstick.com/view/80763/donald-trump-ki-jeet-fix-hai) this [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) to display the image in my [resource](https://www.mindstick.com/blog/43433/top-best-resources-for-women-about-beauty-and-health) to the Image on button press?

## Replies

### Reply by Pravesh Singh

Hi ankit,

This seems to work:

## In app.xaml:

```
<Application.Resources>    <Image x:Key="myImage" Source="C:\Users\Public\Pictures\Sample Pictures\Desert.jpg"/></Application.Resources>
```

## in MainWindow.xaml:

```
<Window x:Class="WpfApplication1.MainWindow"    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    xmlns:local="clr-namespace:WpfApplication1"    Title="MainWindow" Height="350" Width="525"><Grid x:Name="myGrid" Margin="5" Width="500">    <StackPanel>        <Button Content="Load Picture" Click="Button_Click_1"/>        <Image x:Name="ImageHolder"/>    </StackPanel></Grid>
```

## in button click event:

```
    private void Button_Click_1(object sender, RoutedEventArgs e)    {        Image img = Application.Current.Resources["myImage"] as Image;        ImageHolder.Source = img.Source;    }
```

## So in your code you need to do :

[Image](https://www.mindstick.com/articles/23551/an-investigate-distinctive-seafood-restaurant-for-your-image-stamp-character) myImage = Properties.Resources.MyImage as Image;

Image1.Source = myImage.Source;


---

Original Source: https://www.mindstick.com/forum/1503/adding-image-in-run-time

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
