I have the scroll viewer to zoom the image and I zoomed the image and made some changes in the image. Then, I am trying to save an image in button click. In the button click, I have changed the Zoom factor value to 1 and then use the RenderedTargetBitmap class to get the stream of the scroll viewer.
Now I get the zoomed area values only, not able to get the changes which I made the button click. I know RenderedTagetBitmap only return the visible values, but I want the zoomed out values. Please suggest me.
Now I get the zoomed area values only, not able to get the changes which I made the button click.
By testing on my side, if as you described, changed the zoom factor to 1, the RenderedTagetBitmap
can get the whole image correctly which is showed inside ScrollViewer
when zoom factor is 1, not only the zoomed area. Here is the simple testing code:
private async void btnsave_Click(object sender, RoutedEventArgs e)
{
if (RenderedScroll.ChangeView(0, 0, 1, true))
{
RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap();
await renderTargetBitmap.RenderAsync(RenderedScroll, width, height);
RenderedImage.Source = renderTargetBitmap;
}
}
But if I didn't disable the animation of ChangeView
method, the RenderedTagetBitmap
may only take the zoomed area which is same to you. This is caused by that the RenderedTagetBitmap
take the content of ScrollViewer
before ScrollViewer
completed changing view to factor 1 since the changing view animation need a while to complete. In that case, you may wait for a while for the animation playing.
private async void btnsave_Click(object sender, RoutedEventArgs e)
{
if (RenderedScroll.ChangeView(0, 0, 1))
{
await Task.Delay(TimeSpan.FromMilliseconds(500));
RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap();
await renderTargetBitmap.RenderAsync(RenderedScroll, width, height);
RenderedImage.Source = renderTargetBitmap;
}
}
Or just disable the ChangeView
animation as the first code block showed if you didn't need that.