2

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.

leesei
  • 6,020
  • 2
  • 29
  • 51
zirkelc
  • 1,451
  • 1
  • 23
  • 49

1 Answers1

3
        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);
        }
Faisal
  • 623
  • 6
  • 11