Reputation: 562
I got a OutOfmemory error when i create a list of bitmapimage...
What am i supposed to do...?
Thanks for your help ;)
Here is my code :
foreach (var bytearray in imageDataBlocksPresta)
{
if (bytearray != null)
{
MemoryStream ms;
using (ms = new MemoryStream(bytearray, 0, bytearray.Length))
{
BitmapImage photo = new BitmapImage();
photo.DecodePixelHeight = 800;
photo.DecodePixelWidth = 624;
photo.SetSource(ms);//ERROR
listphotoPresta.Add(photo);
}
}
else//si photo null
{
BitmapImage photo = new BitmapImage();
photo.DecodePixelHeight = 800;
photo.DecodePixelWidth = 624;
photo.UriSource = new Uri("/Images/NoImageIcon.jpg", UriKind.RelativeOrAbsolute);
listphotoPresta.Add(photo);
}
Upvotes: 0
Views: 416
Reputation: 331
Try setting photo to null and calling GC.Collect() once you've added it. Like this:
listphotoPresta.Add(photo);
photo = null;
GC.Collect();
Upvotes: 2
Reputation: 4305
Upvotes: 0