【发布时间】:2011-07-11 12:32:31
【问题描述】:
我正在创建一个可以轻松插入图像的 RichTextBox 子类。我提到 this question 开始,但我无法让生成的 RTF 字符串工作。当我尝试设置 RTB 的 SelectedRtf 时,出现“文件格式无效”错误。这是我的代码:
internal void InsertImage(Image img)
{
string str = @"{\pict\pngblip\picw24\pich24 " + imageToHex(img) + "}";
this.SelectedRtf = str; // This line throws the exception
}
private string imageToHex(Image img)
{
MemoryStream ms = new MemoryStream();
img.Save(ms, ImageFormat.Png);
byte[] bytes = ms.ToArray();
string hex = BitConverter.ToString(bytes);
return hex.Replace("-", "");
}
我已经看到了我正在尝试做的工作示例,但使用的是 wmetafiles,但我不想使用这种方法。有什么想法吗?
谢谢,
贾里德
【问题讨论】:
标签: c# .net richtextbox rtf