分享一个RTF转Image的方法,求高手优化
来源:互联网 发布:淘宝运费险退货流程 编辑:程序博客网 时间:2024/06/08 16:55
/// <summary>
/// rtf转image
/// </summary>
/// <returns></returns>
public Image GetImageFromRtf()
{
if (this.SelectionType != RichTextBoxSelectionTypes.Object) return null;
Graphics graphics = null;
MemoryStream stream = null;
Metafile metafile = null;
try
{
var props = this.SelectedRtf.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);
int pich = int.Parse((from x in props where x.Contains("pich") select x).First<string>().Remove(0, 4));
int picw = int.Parse((from x in props where x.Contains("picw") select x).First<string>().Remove(0, 4));
// Get the horizontal and vertical resolutions at which the object is
using (graphics = this.CreateGraphics())
{
xDpi = graphics.DpiX;
yDpi = graphics.DpiY;
}
// Calculate the current width of the image in (0.01)mm
int imageWidth = (int)Math.Round(picw * xDpi / HMM_PER_INCH);
// Calculate the current height of the image in (0.01)mm
int imageHeight = (int)Math.Round(pich * yDpi / HMM_PER_INCH);
var lines = this.SelectedRtf.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
List<byte> imageBytes = new List<byte>();
for (int i = 2; i < lines.Length - 1; i++)
{
for (int j = 0; j < lines[i].Length; j+=2)
{
imageBytes.Add(Byte.Parse(new string(new char[] { lines[i][j], lines[i][j + 1] }),
System.Globalization.NumberStyles.HexNumber));
}
}
stream = new MemoryStream(imageBytes.ToArray());
metafile = new Metafile(stream);
Image img = metafile.GetThumbnailImage(imageWidth, imageHeight, null, IntPtr.Zero);
return img;
}
finally
{
if (graphics != null)
graphics.Dispose();
if (metafile != null)
metafile.Dispose();
if (stream != null)
stream.Close();
}
}
- 分享一个RTF转Image的方法,求高手优化
- 免费的Html转rtf方法
- 一个硬件高手的设计经验分享
- 一个硬件高手的设计经验分享
- 一个硬件高手的设计经验分享
- 一个硬件高手的设计经验分享
- 关于RTF提取图片和文字的方法 (转)
- 某高手毕生精力总结的电脑技巧.rtf
- 分享自己写的一个小工具RGB转十六进制(高手勿喷)
- 求高手写一个止盈止损的存储定时存储过程。
- 求高手解决一个图形与矩阵运算的题目
- 一个VB的外挂,部分源码,求高手完成下
- RTF域的备份(调用AppendRTItem方法)
- 分享一个Image类,里面有一图片切割,clone,等一些方法
- 分享一个格式化文件大小的 C# 方法(转)
- 求SQL高手帮忙建一个触发器
- SEO高手 就是内容优化的高手
- SEO高手 就是内容优化的高手
- 备份
- Linux异步IO操作
- 【Linux从零开始】:0.初识Linux
- json form javascript
- Learning OpenCV第十一章(1)
- 分享一个RTF转Image的方法,求高手优化
- WCF与Web Service的区别
- java synchronized详解(二)
- 笔记.javascript无法执行问题
- Struts2 标签
- 我看过的最好的网络入门书 (来自豆瓣)
- 让工作变得简单而高效的10种方法
- 底座音箱FireDock:专为Kindle Fire设计
- 修改Sql Server表结构时,常用到的Alter语句