[英]C# richtextbox show image from RTF
Why is it that my richtextbox only showed the RTF codes not the image? 为什么我的richtextbox只显示RTF代码而不显示图像? Here is the rtf codes:
这是rtf代码:
{\\pict\\pngblip\\picw800\\pich600\\picwgoal6400\\pichgoal4800\\hex }
{\\ pict \\ pngblip \\ picw800 \\ pich600 \\ picwgoal6400 \\ pichgoal4800 \\ hex}
actually its to long, just deleted some. 实际上它很长,只是删了一些。
but if the format starts with something like -> {rtf........, it showed the image 但如果格式以 - > {rtf ........开头,它显示了图像
Thanks in advance 提前致谢
Assuming the WinForms RichTextBox, then yes, the contents of the RichTextBox has to be a valid RTF document, so it does need to start with an {\\rtf1
element and end with the closing bracket }
. 假设WinForms RichTextBox,那么是的,RichTextBox的内容必须是一个有效的RTF文档,因此它需要以
{\\rtf1
元素开头并以结束括号结束}
。
Example: 例:
{\\rtf1{\\pict\\pngblip\\picw800\\pich600......blah blah blah.....44AE426082}}
{\\ rtf1 {\\ pict \\ pngblip \\ picw800 \\ pich600 ...... blah blah blah ..... 44AE426082}}
If your rtf glob is just a string variable, then you can do something like this: 如果你的rtf glob只是一个字符串变量,那么你可以这样做:
richTextBox1.Rtf = @"{\rtf1" + picText + "}";
To display inline image in a rich textbox you have to do something like this: 要在富文本框中显示内嵌图像,您必须执行以下操作:
//A RichTextBox with an image.
private void ImageRTB()
{
//Create a new RichTextBox.
RichTextBox MyRTB = new RichTextBox();
// Create a Run of plain text and image.
Run myRun = new Run();
myRun.Text = "Displaying text with inline image";
Image MyImage = new Image();
MyImage.Source = new BitmapImage(new Uri("flower.jpg",
UriKind.RelativeOrAbsolute));
MyImage.Height = 50;
MyImage.Width = 50;
InlineUIContainer MyUI = new InlineUIContainer();
MyUI.Child = MyImage;
// Create a paragraph and add the paragraph to the RichTextBox.
Paragraph myParagraph = new Paragraph();
MyRTB.Blocks.Add(myParagraph);
// Add the Run and image to it.
myParagraph.Inlines.Add(myRun);
myParagraph.Inlines.Add(MyUI);
//Add the RichTextBox to the StackPanel.
MySP.Children.Add(MyRTB);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.