C#,WPF的RichTextbox同时显示图片和文字
this.richEdit.Document.Blocks.Clear();
if (string.IsNullOrEmpty(html))
{
return;
}
string newHtml;
HtmlHelper.ReplaceLatexSpanWithImages(html, out newHtml);
string rtf = HtmlToRtfConverter.ConvertHtmlToRtf(newHtml);
if (!string.IsNullOrEmpty(rtf))
{
System.Windows.Forms.RichTextBox rtBox = new System.Windows.Forms.RichTextBox();
rtBox.Rtf = rtf;
string plainText = rtBox.Text;
string[] slplitStr = plainText.Split(new string[] { "\n"},StringSplitOptions.None);
foreach (var s in slplitStr)
{
Clipboard.Clear();
if (File.Exists(s))
{
Bitmap bmp = new Bitmap(s);
System.IntPtr hBmp = bmp.GetHbitmap();
BitmapSource bs = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBmp, System.IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
Clipboard.SetImage(bs);
}
else
{
Clipboard.SetText(s);
}
this.richEdit.Paste();
Clipboard.Clear();
}
//MemoryStream mem = new MemoryStream(ASCIIEncoding.UTF8.GetBytes(rtf));
//this.richEdit.Selection.Load(mem, DataFormats.Rtf);
}