简体   繁体   中英

WP8 WriteableBitmap constructor keeps a lot of memory

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.

内存图

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM