This is a migrated thread and some comments may be shown as answers.

Paste an image from clipboard into RadRichTextBox

3 Answers 183 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Samuel
Top achievements
Rank 1
Samuel asked on 05 Oct 2011, 06:32 PM
Hello,

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

Thanks,
Samuel.

3 Answers, 1 is accepted

Sort by
0
hwsoderlund
Top achievements
Rank 1
answered on 05 Oct 2011, 07:48 PM
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.
0
Samuel
Top achievements
Rank 1
answered on 05 Oct 2011, 07:56 PM
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!
0
Iva Toteva
Telerik team
answered on 10 Oct 2011, 04:26 PM
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 >>

Tags
RichTextBox
Asked by
Samuel
Top achievements
Rank 1
Answers by
hwsoderlund
Top achievements
Rank 1
Samuel
Top achievements
Rank 1
Iva Toteva
Telerik team
Share this question
or