First and foremost, I apologize for my grammatical errors; my first language is Persian (Iran).
I want to display the images in the Datagrid column where the binary are stored in Access.
The following method converts the image to binary:
private static byte[] ImageToBytes(BitmapImage image)
{
byte[] Data;
JpegBitmapEncoder JpegEncoder = new JpegBitmapEncoder();
JpegEncoder.Frames.Add(BitmapFrame.Create(image));
using (System.IO.MemoryStream MS = new System.IO.MemoryStream())
{
JpegEncoder.Save(MS);
Data = MS.ToArray();
}
return Data;
}
I receive the Bitmap image from the method below and then display it in the Image control:
private BitmapImage GetImageFromBytes(byte[] bytes)
{
System.IO.MemoryStream Stream = new System.IO.MemoryStream();
Stream.Write(bytes, 0, bytes.Length);
Stream.Position = 0;
System.Drawing.Image img = System.Drawing.Image.FromStream(Stream);
BitmapImage bitImage = new BitmapImage();
bitImage.BeginInit();
System.IO.MemoryStream MS = new System.IO.MemoryStream();
img.Save(MS, System.Drawing.Imaging.ImageFormat.Jpeg);
MS.Seek(0, System.IO.SeekOrigin.Begin);
bitImage.StreamSource = MS;
bitImage.EndInit();
return bitImage;
}

But the above method for displaying the image in the datagrid does not work properly:

Thanks
