I have to draw a bitmap image using DrawingContext.DrawImage method.
Using the code below everything is working correctly:
BitmapImage myImage = new BitmapImage(); myImage.BeginInit(); myImage.UriSource = new Uri("image.png", UriKind.Relative); myImage.EndInit(); Rect area = new Rect(new Size(myImage.PixelWidth, myImage.PixelHeight)); DrawingVisual myVisual = new DrawingVisual(); using (DrawingContext context = myVisual.RenderOpen()) { context.DrawImage(myImage, area); }
But only if the image does not exceed 2Mb about, i.e. the area (myImage.PixelWidth x myImage.PixelHeight
) is not larger than 10000x10000. In this case the screen remains blank and no any exception is thrown (so I can not tell if there was an error).
How could I fix this problem? Thanks.