Can I use Silverlight's WriteableBitmap to save non-visible parts of my UI to a bitmap?
Asked Answered
L

1

6

Say I have some grid that you need to scroll down to see all of its lines, and I'm interested in saving some lines that are not currently visible as a bitmap. Is it feasible, or do I have to actually scroll down, "take a snapshot", and then scroll up again?

This is a feasibility question, and thus I don't have code to share.

Limn answered 4/8, 2011 at 10:7 Comment(0)
S
4

Yes. You can render any UIElement (and its children) to a writeable bitmap.

When you do that you also specify a transform. That means you can display any part of the UIElement (if you do not want it all).

Whether it is "visible" on screen is completely irrelevant to bitmap rendering. It does not work like a screen grab.

The output cropping is solely down to the size of the target bitmap and the render transform provided.

As an example Silverlight Rotate & Scale a bitmap image to fit within rectangle without cropping uses UIElements that are never part of the visual tree to create a bitmap that is then rendered.

Spermatozoid answered 4/8, 2011 at 10:10 Comment(6)
Thanks. A follow up question - does this also mean that I can save a UIElement not currently visible on screen?Limn
Yes. You can render any UIElement, attached to the visual tree or not. Added link to another [really cool] answer :)Spermatozoid
@TrueBlueAussie where u have added link ?Pend
@User121212: The one and only link in the answer is the one I meant: #6802046Spermatozoid
@TrueBlueAussie My question if i have UIelement means without rendering how to save as image in Silverlight ?Pend
@User121212: Please ask questions as a question on Stack Overflow. The example shown in the link renders the bitmap disconnected from the screen (which is what you want).Spermatozoid

© 2022 - 2024 — McMap. All rights reserved.