Text in encoded PNG or JPEG blurry after encoding from RenderTargetBitmap RRS feed

  • Question

  • I was trying to create a PNG file from a canvas.  The canvas has a image and also three textblocks.  The purpose was to allow the user to move these textblocks around the canvas, and then, save the screenshot to an image.

    The captured image looks ok.  I used RenderTargetBitmap to capture the canvas.  But once I tried to encode the RenderTargetBitmap to the PNG or JPEG, the text becomes very blurry.

    Here is the original pictures:

    Here is the code I used:

    var pixels = await ArrangePicturePage.ArrangedImage.GetPixelsAsync();
    byte[] bytes = pixels.ToArray();
    IRandomAccessStream stream = new InMemoryRandomAccessStream();
    BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, stream);
                    (uint) ArrangePicturePage.ArrangedImage.PixelWidth,
                    (uint) ArrangePicturePage.ArrangedImage.PixelHeight, 
                    96.0, 96.0, bytes);
    await encoder.FlushAsync();
    byte[] resultingBuffer = new byte[stream.Size];
    await stream.ReadAsync(resultingBuffer.AsBuffer(), (uint)resultingBuffer.Length, InputStreamOptions.None);

    The resultingBuffer is the blob that I assume is the PNG or JPEG.  Here is how it looks:

    Is there something wrong with my conversion code that blurred the text?

    Monday, March 16, 2015 3:45 PM

All replies