【发布时间】:2012-10-08 18:24:47
【问题描述】:
我想在 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 picStr=@"{\pict\jpegblip\picw"+width+@"\pich"+height+
@"\picwgoal"+width+@"\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);
}
图片也看不到。它有什么问题。
非常感谢。
【问题讨论】:
标签: c# winforms image richtextbox rtf