将图像与Text C#一起插入RichTextBox中 [英] Insert Image in RichTextBox along with Text C#
本文介绍了将图像与Text C#一起插入RichTextBox中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在C#的富文本框中插入图像,但是到目前为止,我只是失败了.惨了.
I'm trying to insert images in my rich text box in C#, but so far I'm only failing. Miserably.
这是我正在使用的代码:
This is the code that I am using:
Clipboard.SetImage(Image.FromFile(Application.StartupPath + @"\PIC\" + i + ".bmp"));
chat.Paste();
真正的问题是我无法在文本框中同时输入文本和图像.在复制图像后插入文本的那一刻,图像消失了.我无法为此找到解决方案
The real problem is I am not able to put both text and image in the textbox. The moment I insert text after copying the image the image disappears. I am unable to find a solution for this
有人可以帮我吗?请??? 谢谢
Can anybody help me with this? Please??? Thanks
推荐答案
RichTextBox rtb = new RichTextBox();
byte[] headerImage = (byte[])(dr["ImageData"]);
string imageData = string.Empty;
if (headerImage != null && headerImage.Length > 0)
{
Bitmap bmp = new Bitmap(new MemoryStream(headerImage));
MemoryStream ms = new MemoryStream();
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
ms.Position = 0;
imageData = @"{\pict\jpegblip\picw10449\pich3280\picwgoal9924\pichgoal1860\ " + BitConverter.ToString(ms.ToArray()).Replace("-", string.Empty).ToLower() + "}";
ms.Dispose();
}
string finalrtfdata = rtb.Rtf;
finalrtfdata = finalrtfdata.Replace("&ImageHeader&", imageData);
// finalrtfdata contain your image data along with rtf tags.
这篇关于将图像与Text C#一起插入RichTextBox中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文