I am using the UWP image control.
I have rotated the image to 45 degrees by applying the Rotate transform(Angle = 45) now I want to convert the rendered rotated image to stream. So I have tried the RenderTargetBitmap to capture the image but it is not worked. It returns an actual image instead of a rotated image. Please provide any suggestions on this.
var rendererShapeViewBitmap = new RenderTargetBitmap();
InMemoryRandomAccessStream renderedStream = new InMemoryRandomAccessStream();
await rendererShapeViewBitmap.RenderAsync(editorImage);
BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, renderedStream);
IBuffer pixelBuffer = await rendererShapeViewBitmap.GetPixelsAsync();
encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied,
(uint)rendererShapeViewBitmap.PixelWidth, (uint)rendererShapeViewBitmap.PixelHeight, 96, 96, pixelBuffer.ToArray());
await encoder.FlushAsync();
renderedStream.Seek(0);
After getting the stream



You could let the
Imagecontrol within a panel such asStackPanelorGrid, and convert the panel which includes your rotated image to stream by using RenderTargetBitmap class.Update:
The size of
Gridwill adapt to the size of theImagecontrol and the size ofGridis always bigger than the size of theImagecontrol if the image is rotated.You could check the following code as a sample.
Code-behind
Update:
The image stream captured by
RenderTargetBitmapwith anImagecontrol does not include the rotation information. Therefore, you cannot get the rotated image stream only.You could check the following code as a workaround:
Code-behind:
Note, you need to rotate your image around its center with
CenterXandCenterYas 0 andUIElement.RenderTransformOriginalas (0.5,0.5) for simple calculation.