windows-phone-8windows-phonerenderwriteablebitmapmicrosoft.ink

Windows Phone - WriteableBitmap.Render does not work with InkPresenter


I'm using WriteableBitmap.Render to convert an InkPresenter control to a byte array and Image.

This is my code:

        var bitmap = new WriteableBitmap(element, null);
        bitmap.Render(element, null);
        bitmap.Invalidate();

        BitmapImage img;

        using (var ms = new MemoryStream())
        {
            bitmap.SaveJpeg(ms, bitmap.PixelWidth, bitmap.PixelHeight, 0, 85);

            // byte[] bytes = ms.ToArray();
            img = new BitmapImage();
            img.SetSource(ms);
        }

If I save the result (byte array or Image) into IsoladtedStorage, the Image has the correct size but is only black.

I don't have an idea why it does not work because I've already used this method with the Map control.


Solution

  •         using (var stream = new MemoryStream())
            {
                WriteableBitmap dd = new WriteableBitmap(ink, null);
                dd.SaveJpeg(stream, dd.PixelWidth, dd.PixelHeight, 0, 100);
                stream.Seek(0, SeekOrigin.Begin);
                var ml = new MediaLibrary();
                ink.Background = new SolidColorBrush(Colors.White);
                ml.SavePicture(string.Format("Images\\{0}.jpg", Guid.NewGuid()), stream);
                ink.Background = new SolidColorBrush(Colors.Transparent);
            }