Search code examples
windows-phone-7windows-phone-8windows-phonewriteablebitmapex

Resize image from photo album


I want to get a certain photo from the Camera Roll album, resize it and save it to my isolated storage so I can bind to it later - how would I go about it?

    using (var library = new MediaLibrary())
    {
        PictureAlbumCollection allAlbums = library.RootPictureAlbum.Albums;
        PictureAlbum cameraRoll = allAlbums.Where(album => album.Name == "Camera Roll").FirstOrDefault();
        var CameraRollPictures = cameraRoll.Pictures;
    }

Here is how I obtain my photos - my understanding is that I need to somehow write it to a writablebitmap, but I fail to see how to go about it. Please advise


Solution

  • Yes! Of course you have to use WriteableBitmap Class to re-size an image.

    Have a look following code snippet for the same.

    private void DoResize()
            {
                WriteableBitmap wBitmap = new WriteableBitmap(objBitmapImage);
                MemoryStream mStream = new MemoryStream();
                wBitmap.SaveJpeg(mStream, 50, 50, 0, 100);
            }
    

    Hope it helps.