I want to insert a picture into a RichTextBox. I add the picture in coding.
This is the major code, adding a jpg image:
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+"}";
Then I insert the "picStr" to the rtf document. But the image can't be seen. I thought "hexImgStr" maybe wrong. I also generate the "hexImgStr" in another way:
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);
}
The image can't be seen either. What's wrong with it.
Thanks a lot.