c# richBox内容转图片
1.自定义控件,继承richBox
public class RichTextBoxPrintCtrl : RichTextBox
{
//private const double anInch = 14.4;
private const double anInch1 = 150;
private const double anInch2 = 200;
[StructLayout(LayoutKind.Sequential)]
private struct RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;
}
[StructLayout(LayoutKind.Sequential)]
private struct CHARRANGE
{
public int cpMin; //First character of range (0 for start of doc)
public int cpMax; //Last character of range (-1 for end of doc)
}
[StructLayout(LayoutKind.Sequential)]
private struct FORMATRANGE
{
public IntPtr hdc; //Actual DC to draw on
public IntPtr hdcTarget; //Target DC for determining text formatting
public RECT rc; //Region of the DC to draw to (in twips)
public RECT rcPage; //Region of the whole DC (page size) (in twips)
public CHARRANGE chrg; //Range of text to draw (see earlier declaration)
}
private const int WM_USER = 0x0400;
private const int EM_FORMATRANGE = WM_USER + 57;
[DllImport("USER32.dll")]
private static extern IntPtr SendMessage(IntPtr hWnd, Int32 msg, Int32 wParam, Int32 lParam); public int PrintImage(int nStartFrom, Graphics g)
{
RECT rcToPrint = default(RECT);
FORMATRANGE fr = default(FORMATRANGE);
IntPtr iptHdc = IntPtr.Zero;
IntPtr iptRes = IntPtr.Zero;
IntPtr iptParam = IntPtr.Zero;
// Calculate the area to render and print
rcToPrint.Top = 0;
rcToPrint.Bottom = (int)Math.Ceiling((g.VisibleClipBounds.Height * anInch2));
rcToPrint.Left = 0;
rcToPrint.Right = (int)Math.Ceiling((g.VisibleClipBounds.Width * anInch1));
iptHdc = g.GetHdc();
//Indicate character from to character to
fr.chrg.cpMin = nStartFrom;
fr.chrg.cpMax = -1;
//Use the same DC for measuring and rendering point at printer hDC
fr.hdc = fr.hdcTarget = iptHdc;
//Indicate the area on page to print
fr.rc = rcToPrint;
//Get the pointer to the FORMATRANGE structure in memory
iptParam = Marshal.AllocCoTaskMem(Marshal.SizeOf(fr));
Marshal.StructureToPtr(fr, iptParam, false);
//Send the rendered data for printing
iptRes = SendMessage(this.Handle, EM_FORMATRANGE, 1, iptParam.ToInt32());
//Free the block of memory allocated
Marshal.FreeCoTaskMem(iptParam);
//Release the device context handle obtained by a previous call
g.ReleaseHdc(iptHdc);
//Return last + 1 character printer
return iptRes.ToInt32();
}
}
2.引用imageText即是。
Bitmap imageText = new Bitmap(richTextBoxPrintCtrl1.Width, richTextBoxPrintCtrl1.Height);
Graphics g = Graphics.FromImage(imageText);
richTextBoxPrintCtrl1.PrintImage(0, g);
c# richBox内容转图片的更多相关文章
- PHP限制HTML内容中图片必须是本站的方法
本文实例讲述了PHP限制HTML内容中图片必须是本站的方法.分享给大家供大家参考.具体实现方法如下: 1. PHP代码如下: <?php $dom = new DOMDocument; $dom ...
- 将UIWebView显示的内容转为图片和PDF
今天开发MarkEditor时要用到将 UIWebView 中显示的内容转为图片,方便转发到各个社交网络(Twiiter,Facebook,Weibo),这样内容就不受长度限制,类似于长微博. 之前关 ...
- 为CKEDITOR内容中图片加上 图片服务器路径
做网站的时候,前台和后台是分开的, 用了CKEDITOR上传图片,但是发现内容带图片的时候,前台Web浏览的时候是一个红X,一看路径不对,上传的到数据库中的是相对的虚拟路径,例如:<img al ...
- 将PPT文件内容转换为图片放在Email邮件正文中发送
通过Email推送统计报告.一般除了要求将PPT报告文件作为附件发给用户,同时希望将报告内容在邮件中直观展示. 一份统计报告中经常包含柱状图.饼图.好看的图表,这些信息要直接在Email中展示比较复杂 ...
- python scrapy爬取知乎问题和收藏夹下所有答案的内容和图片
上文介绍了爬取知乎问题信息的整个过程,这里介绍下爬取问题下所有答案的内容和图片,大致过程相同,部分核心代码不同. 爬取一个问题的所有内容流程大致如下: 一个问题url 请求url,获取问题下的答案个数 ...
- Lodop导出图片,导出单页内容的图片
用如下语句设置图片的格式,设置导出的图片初识的默认名称,Lodop可以把打印内容导出成图片. LODOP.SET_SAVE_MODE("SAVEAS_IMGFILE_EXENAME" ...
- dedecms织梦手机端文章内容页图片不能自适应解决方法
dedecms织梦手机端文章内容页图片不能自适应解决方法: 方法一修改手机端文章页模板代码: 找到并打开手机端的文章内容页模板,将里面的{dede:field.body/}标签修改一下,改为如下的标签 ...
- android截屏:保存一个view的内容为图片并存放到SD卡
项目中偶尔会用到截屏分享,于是就有了下面这个截屏的方法~ 下面得saveImage()方法就是保存当前Activity对应的屏幕所有内容的截屏保存. private void saveImage() ...
- 基于内容的图片检索CBIR(Content Based Image Retrieval)简介
传统的图像检索过程,先通过人工对图像进行文字标注,再利用关键字来检索图像,这种依据图像描述的字符匹配程度提供检索结果的方法,简称“以字找图”,既耗时又主观多义.基于内容的图像检索客服“以字找图”方式的 ...
随机推荐
- Read a large file with python
python读取大文件 较pythonic的方法,使用with结构 文件可以自动关闭 异常可以在with块内处理 with open(filename, 'rb') as f: for line in ...
- linux 学习第十四天(Apache安装、基于ip、基于域名、基于端口配置)
一.虚拟主机 A.基于IP地址 B.基于域名 C.基于端口号 复习yum仓库挂载 mkdir /media/cdrom mount /dev/cdrom /media/cdrom/ vim /et ...
- jar下载地址
java开发难免需要下载额外的jar,推荐一个地址 http://www.java2s.com/Code/Jar/CatalogJar.htm
- swiper在vue中正确的使用方法
1.安装swiper,执行npm install vue-awesome-swiper --save命令 2.在main.js中添加下面三行 import 'swiper/dist/css/swipe ...
- Python 装饰器装饰类中的方法(转)
def catch_exception(origin_func): def wrapper(self, *args, **kwargs): try: u = origin_func(self, *ar ...
- TINY4412:移植uboot、内核和挂接网络文件系统
开发环境: 单板:TINY4412-1611 系统:Ubuntu 16.04 64位 编译工具链:arm-linux-gcc-4.3.2 uboot版本:uboot_tiny4412-20130729 ...
- 20155336 2016-2017-2《Java程序设计》课程总结
20155336虎光元<Java程序设计>课程总结 一.每周作业 第一周学习总结:http://www.cnblogs.com/hxl681207/p/6457919.html 第二周学习 ...
- 【转载】Ogre3d 2.1 源码编译安装教程
原文:Ogre3d 2.1 源码编译安装教程 今年是3D手游年,今年也是游戏引擎战争进入白热的一年. 移动游戏的红海时代,让各大端游也忍不住纷纷伸出大白腿,Unreal.CryEngine纷纷宣布自己 ...
- LOJ #2585. 「APIO2018」新家
#2585. 「APIO2018」新家 https://loj.ac/problem/2585 分析: 线段树+二分. 首先看怎样数颜色,正常的时候,离线扫一遍右端点,每次只记录最右边的点,然后查询左 ...
- 06004_Redis的启动、使用和停止
1.Redis的启动 (1)前端模式启动 ①直接运行bin/redis-server将以前端模式启动:切换到 /usr/local/redis/bin目录下,然后./redis-server : ②前 ...