Due to performance reasons, I have to rescale a very large BitmapImage (e.g. 45000*10000 pixels) during loading. As the image can be zoomed, I cannot simply specify a fixed size but would reduce the pixel size by some (later dynamic) factor:
image = new BitmapImage();
var memory = new MemoryStream();
using (var stream = File.OpenRead(fileName))
{
stream.CopyTo(memory);
}
memory.Position = 0;
var tempImage = new BitmapImage();
tempImage.BeginInit();
tempImage.CacheOption = BitmapCacheOption.OnDemand;
tempImage.StreamSource = memory;
tempImage.EndInit();
memory.Position = 0;
image.BeginInit();
image.CacheOption = BitmapCacheOption.OnDemand;
image.CreateOptions = BitmapCreateOptions.DelayCreation;
image.StreamSource = memory;
image.DecodePixelWidth = tempImage.PixelWidth/2;
image.DecodePixelHeight = tempImage.PixelHeight/2;
image.EndInit();
After initialization is finished, the PixelWidth is equal to the DecodePixelWidth. However, I would somehow need to access the original width and hight of the image. Is it somehow possible to get this information directly out of the image object, or do I have to store it somewhere else?
The problem is, that BitmapImage is sealed, so I cannot extend the class with the new parameters - however, I would like to pass the result image to the source of an Image
control.