110,499
社区成员
发帖
与我相关
我的任务
分享
/// <summary>
/// 添加一个文件资源到RTF数据
/// </summary>
/// <param name="p_FileFullPath">文件路径</param>
public void AddFile(string p_FileFullPath)
{
byte[] _FileBytes = File.ReadAllBytes(p_FileFullPath);
Image _Image = Image.FromStream(new MemoryStream(_FileBytes));
string _Guid = BitConverter.ToString(Guid.NewGuid().ToByteArray()).Replace("-", "");
StringBuilder _RtfText = new StringBuilder(@"{\rtf1\ansi\ansicpg936\deff0\deflang1033\deflangfe2052{\fonttbl{\f0\fnil\fcharset134 \'cb\'ce\'cc\'e5;}}\uc1\pard\lang2052\f0\fs18{\object\objemb{\*\objclass Paint.Picture}");
int _Width = _Image.Width * 15;
int _Height = _Image.Height * 15;
_RtfText.Append(@"\objw" + _Width.ToString() + @"\objh" + _Height.ToString());
_RtfText.AppendLine(@"{\*\objdata");
_RtfText.AppendLine(@"010500000200000007000000504272757368000000000000000000" + BitConverter.ToString(BitConverter.GetBytes(_FileBytes.Length + 20)).Replace("-", ""));
_RtfText.Append("7A676B65" + _Guid); //标记
_RtfText.AppendLine(BitConverter.ToString(_FileBytes).Replace("-", ""));
_RtfText.AppendLine(@"0105000000000000}{\result{\pict\wmetafile0}}}}");
base.SelectedRtf = _RtfText.ToString();
}