Paste an image from clipboard into RadRichTextBox

4 posts, 0 answers
  1. Samuel
    Samuel avatar
    3 posts
    Member since:
    Sep 2011

    Posted 05 Oct 2011 Link to this post

    Hello,

    Can I paste an image from clipboard into RadRichTextBox(silverlight 4 application)? or is there any other control available for that?

    Thanks,
    Samuel.
  2. hwsoderlund
    hwsoderlund avatar
    419 posts
    Member since:
    Aug 2006

    Posted 05 Oct 2011 Link to this post

    This is unfortunately not possible because of a limitation in the Silverlight plugin itself. Silverlight can only access plain text in the clipboard. As far as I know this will not change in Silverlight 5. Let us hope that Silverlight 6, if that ever happens, will extend the clipboard support to rich text and images.
  3. DevCraft banner
  4. Samuel
    Samuel avatar
    3 posts
    Member since:
    Sep 2011

    Posted 05 Oct 2011 Link to this post

    I think in one of your previous posts you have answered saying:

    If you use the built-in "Insert Image" function in the RichTextBox, the images will be inserted inline in the xaml as base64-encoded strings.

    Can I please have a step by step explanation for this? If you have an example code that will be great.

    Appreciate your help!
  5. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 10 Oct 2011 Link to this post

    Hello Samuel,

    Henrik's right about the Silverlight clipboard and the options it provides. That is why it would not be possible to obtain anything more than plain text from the clipboard and paste it in the rich text box.

    When it comes to the InsertImage method of RadRichTextBox, it takes a stream and an extension, which specifies what is the format of the image and inserts the image at the current caret position. For example, this method is used when the InsertPictureCommand is triggered. The same method is used in our online demo when you drop an image file on the document:

    private void editor_Drop(object sender, DragEventArgs e)
    {
        FileInfo[] droppedFiles = e.Data.GetData(DataFormats.FileDrop) as FileInfo[];
     
        foreach (FileInfo droppedFile in droppedFiles)
        {
            if (this.IsSupportedImageFormat(droppedFile.Extension))
            {
                using (Stream imageStream = droppedFile.OpenRead())
                {
                    this.editor.InsertImage(imageStream, droppedFile.Extension);
                }
            }
        }
    }
     
    private bool IsSupportedImageFormat(string p)
    {
        return (p == ".jpg") ||
            (p == ".jpeg") ||
            (p == ".png") ||
            (p == ".bmp");
    }

    Therefore, as long as you have the image stream and know its format, you can insert it in the document.

    Greetings,
    Iva
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top