Quantcast
Channel: Extended WPF Toolkit™ Community Edition
Viewing all articles
Browse latest Browse all 4964

Commented Unassigned: RichTextBox crashes with OutOfMemoryException when pasting in large image [22346]

$
0
0
I tried pasting in a 4500x3250 image into the RichTextBox, and it crashes. The RichTextBox declared as follows:

```
<toolkit:RichTextBox x:Name="richTextBox"
Grid.Row="1"
Grid.ColumnSpan="2"
Margin="10"
MaxHeight="345"
ScrollViewer.VerticalScrollBarVisibility="Auto"
Text="{Binding CurrentlySelectedNotePage.TextInRTF}">
<toolkit:RichTextBoxFormatBarManager.FormatBar>
<toolkit:RichTextBoxFormatBar />
</toolkit:RichTextBoxFormatBarManager.FormatBar>
</toolkit:RichTextBox>
```

If I try to paste the same image into a standard System.Windows.Controls.RichTextBox, the paste is successful.

And if it isn't possible to paste larger images into the WPF Toolkit RichTextBox, then maybe there should be a more elegant way of handling this?
Comments: ** Comment from web user: BoucherS **

Hi,

The RichTextBox from the Toolkit formats the Text (RTF, XAML or PlainText) and in this case (RTF), the formatting causes the OutOfMemory exception.
The problem is in file Xceed.Wpf.Toolkit/RichTextBox/Formatters/RtfFormatter.cs, in method "GetText( FlowDocument document )".
A MemoryStream is created and a TextRange tries to saves its data in this MemoryStream, in RtfFormat.
There is enough memory :
-when using a build in x64
-when using small images
-when using XamlFormat and PlainTextFormat

But you fall in a specific case (x86, large image, RtfFormat) where there is not enough memory to proceed the action. This method can always return an empty string and it will work, but the Text property will not be formatted in RTF.

The standard RichTextBox doesn't format the Text.

You can always try another formatting, or try to reduce the image size before adding it to the Toolkit's RichTextBox.


Viewing all articles
Browse latest Browse all 4964

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>