我想将图片插入RichTextBox。我在编码中添加图片。无法将图片插入RichTextBox
这是主要的代码,添加一个JPG图片:
MemoryStream memoryStream = new MemoryStream();
img.Save(memoryStream,System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] bytes = memoryStream.ToArray();
String width = img.Width.ToString();
String height = img.Height.ToString();
String hexImgStr=BitConverter.ToString(bytes, 0).Replace("-","");
String [email protected]"{\pict\jpegblip\picw"[email protected]"\pich"+height+
@"\picwgoal"[email protected]"\pichgoal"+height+" "+hexImgStr+"}";
然后,我将 “picStr” 的RTF文档。但形象无法看到。我认为“hexImgStr”可能是错误的。我还以另一种方式生成“hexImgStr”:
FileStream fs = new FileStream(imgPath,FileMode.Open);
BinaryReader br=new BinaryReader(fs);
//byte[] bytes=new byte[fs.Length];
String hexImgStr="";
for (long i = 0; i < fs.Length; i++)
{
//bytes[i] = br.ReadByte();
hexImgStr +=Convert.ToString(br.ReadByte(),16);
}
图像也无法看到。它出什么问题了。
非常感谢。