Hi
I am trying to create an XImage from a jpg that I have as a bytearray. I would like to avoid saving it to file and also there is a bug in the WPF XImage.FromFile method not releasing the file.
Problem is that the image seems not to be treated as a jpg which makes the pdf file huge compared to using the .FromFile method. I am not sure if I am getting the conversion from bytearray to BitmapSource wrong or if there is a bug in pdfsharp not recognizing the jpg properly.
Thanks,
Espen
This is my code:
Code:
XImage image = XImage.FromBitmapSource(BitmapSourceFromBytes(ImageBytes));
public static BitmapSource BitmapSourceFromBytes(byte[] ImageBytes)
{
MemoryStream ms = new MemoryStream(ImageBytes);
Bitmap sourceImage = (Bitmap)Bitmap.FromStream(ms);
ms.Dispose();
return System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(sourceImage.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty,
System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
}