Rendering RadRichTextPageView to an Image

8 posts, 0 answers
  1. Oliver
    Oliver avatar
    36 posts
    Member since:
    Apr 2011

    Posted 10 Apr 2011 Link to this post

    I need to generate a preview thumbnail image of a RadDocument. Unfortunately I cannot get it to work:

    DocumentViewManager viewManager = new DocumentViewManager();
    XamlFormatProvider xamlProvider = new XamlFormatProvider();
    viewManager.Document = xamlProvider.Import(xamlProvider.Export(VM.Document));
    viewManager.Document.LayoutMode = DocumentLayoutMode.Paged;
    RadRichTextPageView view = new RadRichTextPageView();
    view.PageIndex = 0;
    ScaleTransform transform = new ScaleTransform();
    transform.ScaleX = 0.4;
    transform.ScaleY = 0.4;
    view.RenderTransform = transform;
    view.ViewManager = viewManager;
    view.PageIndex = 0;

    var writeableBitmap = new WriteableBitmap(200, 200);
    view.InvalidateMeasure();
    writeableBitmap.Render(Editor, null);
    writeableBitmap.Invalidate();

    var image = new Image();
    image.Width = 200;
    image.Height = 200;
    image.Source = writeableBitmap;

    var wnd = new ChildWindow();
    wnd.Content = image;
    wnd.Show();

    Any suggestions?

  2. Ivailo Karamanolev
    Admin
    Ivailo Karamanolev avatar
    276 posts

    Posted 13 Apr 2011 Link to this post

    Hello Oliver,

    For some reason, when capturing the RadRichTextPageView as a bitmap using WriteableBitmap, Silverlight doesn't render it correctly. We are making an effort to make it work, but we don't currently have a solution to the problem. What we recommend for now is to render the document dynamically using RadRichTextPageView. We are sorry for any inconvenience caused.

    Kind regards,
    Ivailo
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Oliver
    Oliver avatar
    36 posts
    Member since:
    Apr 2011

    Posted 13 Apr 2011 Link to this post

    Ivailo, thanks for the update. What do you mean with "render the document dynamically"?
  4. Ivailo Karamanolev
    Admin
    Ivailo Karamanolev avatar
    276 posts

    Posted 15 Apr 2011 Link to this post

    Hi Oliver,

    I'm sorry I didn't make myself clear. What I meant was, that I recommend you to put a RadRichTextPageView with the document page you want to show (render the document dynamically, instead of statically, e.g. from a pre-rendered bitmap). This will carry a performance penalty, as RadRichTextPageView is much slower than rendering a simple bitmap, but we haven't found a viable solution yet.

    All the best,
    Ivailo
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Oliver
    Oliver avatar
    36 posts
    Member since:
    Apr 2011

    Posted 15 Apr 2011 Link to this post

    I think this is a misunderstanding. My sample code only used the ChildWindow for showcasing the effect. The desired use is to render the thumbnail and store somewhere as JPG.
  6. Ivailo Karamanolev
    Admin
    Ivailo Karamanolev avatar
    276 posts

    Posted 15 Apr 2011 Link to this post

    Hi Oliver,

    Rendering the document on an image using WriteableBitmap produces artifacts. We currently don't know of a way to render the document to an image.

    Greetings,
    Ivailo
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  7. Oliver
    Oliver avatar
    36 posts
    Member since:
    Apr 2011

    Posted 15 Apr 2011 Link to this post

    Yes I've understood that but your last comment sounded a bit like as if you were trying to offer a workaround (which I didn't get by the way :)

    One question though, until now I haven't found a single control that refused to render to a WriteableBitmap. How comes the RadRichTextBox is so different?
  8. Ivailo Karamanolev
    Admin
    Ivailo Karamanolev avatar
    276 posts

    Posted 18 Apr 2011 Link to this post

    Hi Oliver,

    Actually, if the RadRichTextPageView is already present in the visual tree and shown on the screen, taking a snapshot of it works correctly. If it is not, however, the text inside it gets overlapped, which is obviously undesired. Unfortunately, adding it to the visual tree on-the-fly doesn't help. We're not sure exactly why Silverlight fails to render it correctly if it hasn't been show previously and thus, we're unable to fix the issue.

    Greetings,
    Ivailo
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top