Im trying to set the Source of the Image Control, im getting the Bitmap from an Event every 2 seconds . What ive tried first is setting the Source without binding.
public void FiletransferImage(string _id, Bitmap _Image)
{
try {
imgDesktop.Source = ToBitmapSource(_Image);
}
catch (Exception ex) {
MessageBox.Show(ex.Message);
}
}
public static BitmapSource ToBitmapSource(System.Drawing.Bitmap source)
{
BitmapSource bitSrc = null;
var Bitmap_ = source.GetHbitmap();
try {
bitSrc = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
Bitmap_,
IntPtr.Zero,
Int32Rect.Empty,
BitmapSizeOptions.FromEmptyOptions());
}
catch (Exception ex) {
bitSrc = null;
}
finally {
}
return bitSrc;
}
but the Image Control doesnt display the Image. Ive tried also to Bind the Image
Image Name="imgDesktop" Source={Binding ImgSource}">
public ImageSource YourImage {get;set;}
anybody an idea what im making wrong?
EDIT: Ive found an solution i converted a the byte array to a Bitmap Image and that worked for me:
public void GetImage(byte[] buffer)
{
BitmapImage img = new BitmapImage();
img.BeginInit();
img.StreamSource = new MemoryStream(buffer);
img.EndInit();
this.imgDesktop.Source = img;
}