I'm using this method for converting a Bitmap to a BitmapImage I found on SO. It's not setting the Width and Height of the BitmapImage correctly.
private BitmapImage BitmapToBitmapImage(System.Drawing.Bitmap bitmap)
{
Console.WriteLine("Conversion Bitmap Size: {0}, {1}", bitmap.Width, bitmap.Height);
using (MemoryStream memory = new MemoryStream())
{
bitmap.Save(memory, System.Drawing.Imaging.ImageFormat.Png);
memory.Position = 0;
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.StreamSource = memory;
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.EndInit();
Console.WriteLine("Bitmap Size: {0}, {1}", bitmapImage.Width, bitmapImage.Height);
return bitmapImage;
}
}
When passing in a Bitmap with the size of 1920x350 I get the following output.
Conversion Bitmap Size: 1920, 350
Bitmap Size: 2559.67994453276, 466.608323222118
Does anyone know what's causing this and how to fix it?