Approved
Last Updated: 30 May 2018 06:51 by ADMIN
ADMIN
Martin Ivanov
Created on: 03 Apr 2017 10:24
Category: RichTextBox
Type: Bug Report
0
RichTextBox: Images are pasted empty when copied from MS Paint, MS Snipping Tool
In some cases when an image is copied from an external source and pasted in the rich text box, the image is not displayed. This is caused by the Clipboard.GetImage() method used internally by the control. 

To work this around, you can subscribe for the CommandExecuting event of RadRichTextBox and manually get the image from the clipboard.

private void Rtb_CommandExecuting(object sender, Telerik.Windows.Documents.RichTextBoxCommands.CommandExecutingEventArgs e)

{
	PasteCommand command = e.Command as PasteCommand;
	if (command != null && (Clipboard.GetData("DeviceIndependentBitmap") != null))
	{
		//Get the image stream from the clipboard.
		//You can check the following blog post for an approach which you can use to get the image properly:
		//https://www.thomaslevesque.com/2009/02/05/wpf-paste-an-image-from-the-clipboard/
		this.radRichTextBox.InsertImage(imageStream, "jpeg");
		e.Cancel = true;
	}
}	
(Total attached files size should be smaller than 20mb. Allowed extensions: .zip, .rar, .jpg, .png, .gif)
0 comments