Вопрос

I am trying to use the WriteableBitmap object because I need it for rotating images and saving images to the Isolated Storage of my app.

The problem is, it uses so much memory it eventually causes an out of memory exception.

Here is a picture of the memory usage of my App, with the picture link here for better viewing.

Memory Chart

Here's an instance of where I use a WriteableBitmap:

        WriteableBitmap picture = new WriteableBitmap(PictureCanvas, null);

        using (var memoryStream = new MemoryStream())
        {
            picture.SaveJpeg(memoryStream, picture.PixelWidth, picture.PixelHeight, 0, 100);

            using (var myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (IsolatedStorageFileStream fileStream = new IsolatedStorageFileStream(Globals.OVERLAY_FILE_NAME, FileMode.Create, myIsolatedStorage))
                {
                    fileStream.Write(memoryStream.ToArray(), 0, memoryStream.ToArray().Length);
                    fileStream.Close();
                }
            }
        }

        picture = picture.Crop(0, 0, 1, 1);

I try cropping the image to make it take up less memory, but that doesn't do anything.

I am using the WriteableBitmap extensions library here and in the front page it mentions a Dispose() method, but I don't see it in my App.

If someone could please tell me how to get around this problem or point me somewhere I can find a possible solution, that would be awesome!

Это было полезно?

Решение

I'm having a similar issue and still investigating but at least a small tip I can give : if possible get rid of the MemoryStream and write directly to the fileStream like so :

    WriteableBitmap picture = new WriteableBitmap(PictureCanvas, null);
    using (var myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
    using (IsolatedStorageFileStream fileStream = new IsolatedStorageFileStream(Globals.OVERLAY_FILE_NAME, FileMode.Create, myIsolatedStorage))
    {
        picture.SaveJpeg(fileStream, picture.PixelWidth, picture.PixelHeight, 0, 100)
    }

This should buy you some memory.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top