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

PNG images not always displaying properly

3 Answers 215 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Frank
Top achievements
Rank 1
Frank asked on 09 Apr 2012, 02:22 PM
Hello,

My development team is currently evaluating the trial version of the RichTextBox to find out whether or not it will meet our current application requirements, one of which is pasting images.  Our users often take screenshots using an application called SnagIt and they need to be able to paste those screenshots into the editor.  

We are encountering some issues when pasting PNG images, but the behavior varies depending on the source of the image.  If we use Microsoft's Snipping Tool to take the screenshot, it pastes into the editor successfully.  However, if we use SnagIt, or even open an image in Microsoft Paint and then try to copy and paste it, the cursor in the textbox moves as if an image was pasted, but no image is displayed.  The area where the image should be is a white box.

We have done no customization of the RichTextBox or anything.  All I did was simply drag the control from the Visual Studio Toolbox onto the WPF canvas.

I have not seen any other posts where anyone has encountered this same issue.  I'm hoping someone has perhaps noticed this same issue before, or to bring it to the attention of the developers as a potential bug that needs to be fixed.  I've attached an image showing how the editor looks exhibiting successful pasting behavior and the unsuccessful behavior.

Thanks,

Frank

3 Answers, 1 is accepted

Sort by
0
Accepted
Iva Toteva
Telerik team
answered on 09 Apr 2012, 03:18 PM
Hello Frank,

Thank you for getting to us about this issue.

Similar issues have been reported when pasting images from MS Paint. When we investigated the problem, it turned out to be a common problem with corrupted data being saved in the clipboard from some programs. There is more information about this issue here.

Unfortunately, the workaround which can be implemented based on the description and code in the blog, is to save all images to a memory stream first. As this may hinder the overall performance, we are refraining from implementing the workaround in the editor. The good news is that you can workaround it on your end quite easily. All you need to do is to handle the CommandExecuting event of RadRichTextBox like this:

void editor_CommandExecuting(object sender, Telerik.Windows.Documents.RichTextBoxCommands.CommandExecutingEventArgs e)
{
    PasteCommand command = e.Command as PasteCommand;
    if (command != null && Clipboard.ContainsImage())
    {
        BitmapSource imageSource = Clipboard.GetImage();
        using (MemoryStream stream = new MemoryStream())
        {
            JpegBitmapEncoder encoder = new JpegBitmapEncoder();
            encoder.Frames.Add(BitmapFrame.Create(imageSource));
            encoder.Save(stream);
            stream.Seek(0, SeekOrigin.Begin);
            ((RadRichTextBox)sender).InsertImage(stream, "jpeg");
            e.Cancel = true;
        }
    }
}

You can also track this PITS issue item in order to be notified when the workaround is implemented in the editor, making this code redundant.

I hope this helps.

Regards,
Iva Toteva
the Telerik team

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

0
Frank
Top achievements
Rank 1
answered on 09 Apr 2012, 03:42 PM
Iva,

We had already figured out the work-around, but it seems like the images lose a bit of quality when converted to JPEG.  We were hoping for a better solution, but we definitely appreciate the response.  I will track the PITS issue item you provided a link to.

Thanks,

Frank
0
Robert
Top achievements
Rank 1
answered on 16 Nov 2012, 11:48 AM
I've also noticed quality issues with PNG images.
I will have to try a different format.
Tags
RichTextBox
Asked by
Frank
Top achievements
Rank 1
Answers by
Iva Toteva
Telerik team
Frank
Top achievements
Rank 1
Robert
Top achievements
Rank 1
Share this question
or