WPF show image problem
I have a problem showing a simple image in WPF:
There is a web service which returns a byte array.
MemoryStream stream = new MemoryStream(barrImg);
FileStream fs = new FileStream(@"c:\\temp\\text.jpg", System.IO.FileMode.OpenOrCreate);
fs.Write(barrImg, 0, barrImg.Length);
fs.Flush();
fs.Close();
for test purposes I write the array to a file - no problem viewing this picture!
Then I put the image from the file into an property of the class for transfer, as shown in many other explanations:
BitmapImage bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.UriSource = new Uri(@"c:\\temp\\text.jpg");
bitmap.EndInit();
imageFromDatabase = new Image();
imageFromDatabase.Source = bitmap;
The property is defined as follows:
private Image _imageFromDatabase;
public Image imageFromDatabase
{
get { return _imageFromDatabase; }
set
{
_imageFromDatabase = value;
}
}
In the display class I have the following (the filling of the property is executed elsewhere and works):
picture1 = wsh.imageFromDatabase;
picture1.Height = double.NaN;
picture1.Refresh();
But, nothing is shown in the picture.
The xaml file shows
<Image Height="100" Name="picture1" Stretch="Fill" Width="Auto" />
for the pictu开发者_Go百科re1 element.
Any ideas?
Thanks
Axel
Have you tried setting the Source
property?
picture1.Source = wsh.imageFromDatabase.Source;
精彩评论