我正在創建一個可以輕鬆插入圖像的RichTextBox子類。我提到this question開始,但我不能讓生成的RTF字符串工作。當我嘗試設置RTB的SelectedRtf時,它以「文件格式無效」出錯。這裏是我的代碼:在C#中插入圖像到RTF文檔中
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的例子,但我寧願不要使用該方法。有任何想法嗎?
感謝,
賈裏德
插入圖片可以正常工作,但剪貼板內容在Win8 x64中無法恢復。在XP中,它的作品。 – AlexP11223 2013-04-11 06:49:00
不能恢復XP 32中的剪貼板... – 2014-10-08 09:30:26