我想將圖片插入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);
}
圖像也無法看到。它出什麼問題了。
非常感謝。