Note that there are some explanatory texts on larger screens.

plurals
  1. POReduce application memory for cropped image in C# WPF
    primarykey
    data
    text
    <p>We're displaying cropped images in our WPF application by creating a new CroppedImage from the original bitmap. but when we look at application memory it's the same for displaying cropped images as it is for displaying the original image. This is perhaps not very strange because the CroppedImage keeps a reference to the original bitmap. But is it somehow possible to create a cropped image as a new bitmap image without the reference to the original bitmap and by doing that reducing application memory?</p> <p>Some code for how to do this would be highly appreciated.</p> <p>Thanks for help!</p> <p>[EDIT] Here is the code for creating the cropped image:</p> <pre><code> public class TheImage : ViewModelBase { public BitmapSource CroppedImage { get; private set; } public TheImage(byte[] imageData) { var bitmapImage = CreateBitmapSource(imageData); var croppingRectangle = CalculateCropRectangle(bitmapImage.PixelWidth, bitmapImage.PixelHeight); CroppedImage = new CroppedBitmap(bitmapImage, croppingRectangle); } private static BitmapImage CreateBitmapSource(byte[] imageData) { var bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.StreamSource = new MemoryStream(imageData); bitmapImage.EndInit(); return bitmapImage; } private static Int32Rect CalculateCropRectangle(int pixelWidth, int pixelHeight) { int width = 256; int height = 256; int x = (pixelWidth - width) / 2; int y = (pixelHeight - height) / 2; return new Int32Rect(x, y, width, height); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload