I am working on a Windows Phone application in Xamarin with MvvmCross. In this application the user selects some images from his phone. They get displayed in a list and the user then does stuff with them.
I am using FileOpenPicker for the file selection and from those files i create BitmapImages to display
foreach (StorageFile file in args.Files) {
BitmapImage thumbnail = new BitmapImage();
thumbnail.DecodePixelType = DecodePixelType.Physical;
try {
using (IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read)) {
thumbnail.DecodePixelHeight = 70;
thumbnail.DecodePixelWidth = 70;
thumbnail.SetSource(fileStream);
fileStream.Dispose();
}
}
catch (OutOfMemoryException e) {
Mvx.Trace("MEMORY IS FULL");
}
After some other code i put these BitmapImages in a ObservableCollection and display them like this
<Image Style="{StaticResource imageListImage}" Source="{Binding Thumbnail}"/>
Nothing special about that. The test images that i am using have a total size of 34 MB. Using the performance and diagnostics tool from VS i was able to determine that the memory usage of the app at start was around 16 Mb. When i loaded the test images in to the app it shot up to 58 MB. as if it still used the full size of the images. and (Just for testing) when i took the decodepixelheight and width away it rocketed to about 350 MB. I have absolutely no idea why it is using so much memory for the images.
Because the application must be able to use lots more and bigger images I need to find a way to cut down on the memory usage. Does anyone know a way how I can do this?