Ok, there is countless from byte to String and etc, but i simply can't find anything on how i can convert the resource files visual studio so nicely convert into a byte[] for me no matter what i do, into a normal Image so i can actually use it in my C# code?
Asked
Active
Viewed 4,134 times
0
-
Show your codezzzzz.. – Soner Gönül May 07 '13 at 08:46
-
1https://www.google.com/search?q=byte+array+to+image+c%23 – ken2k May 07 '13 at 08:47
-
1This *basically* relates to this similar question http://stackoverflow.com/questions/8897210/byte-to-bitmapimage - just set the `Source` on your `Image` to the `BitmapImage` once done – Marc Gravell May 07 '13 at 08:51
2 Answers
1
You can use a valueconverter to do this -
public class InMemoryImageValueConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var image = new BitmapImage();
var memoryStream = new MemoryStream((byte[])value);
image.SetSource(memoryStream);
return image;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return null;
}
}
then you can use that in the Image control as
<Image Source="{Binding TheBytes, Converter={StaticResource InMemoryImage}}" />

Stuart
- 66,722
- 7
- 114
- 165
0
if your image is resource of the application then you can do as following
Uri uriR = new Uri("/WP7SampleProject3;component/images/appbar.feature.email.rest.png", UriKind.Relative);
BitmapImage imgSourceR = new BitmapImage(uriR);
this.imageR.Source = imgSourceR;

Damith
- 62,401
- 13
- 102
- 153