/// 将容器内容转成图片导出,这里的controller就是this
/// </summary>
private void OutTheControllerToPic()
{
Bitmap bitmap = new Bitmap( this.Width, this .Height);
DrawToBitmap( this, bitmap, new Rectangle(0, 0, this.Width, this .Height));
bool isSave = true ;
SaveFileDialog saveImageDialog = new SaveFileDialog();
saveImageDialog.Title = "图片保存" ;
saveImageDialog.Filter = @"png|*.png|jpeg|*.jpg|bmp|*.bmp|gif|*.gif" ;
if (saveImageDialog.ShowDialog() == DialogResult.OK)
{
string fileName = saveImageDialog.FileName.ToString();
if (fileName != "" && fileName != null)
{
string fileExtName = fileName.Substring(fileName.LastIndexOf(".") + 1).ToString();
System.Drawing.Imaging. ImageFormat imgformat = null ;
if (fileExtName != "" )
{
switch (fileExtName)
{
case "jpg" :
imgformat = System.Drawing.Imaging. ImageFormat.Jpeg;
break;
case "bmp" :
imgformat = System.Drawing.Imaging. ImageFormat.Bmp;
break;
case "gif" :
imgformat = System.Drawing.Imaging. ImageFormat.Gif;
break;
case "png" :
imgformat = System.Drawing.Imaging. ImageFormat.Png;
break;
default:
MessageBox.Show("只能存取为: jpg,bmp,gif,png 格式" );
isSave = false;
break;
}
}
//默认保存为JPG格式
if (imgformat == null )
{
imgformat = System.Drawing.Imaging. ImageFormat.Jpeg;
}
if (isSave)
{
try
{
bitmap.Save(fileName, imgformat);
MessageBox.Show("图片已经成功保存!" );
}
catch
{
MessageBox.Show("保存失败,你还没有截取过图片或已经清空图片!" );
}
}
}
}
}
[ DllImport("user32.dll" , CharSet = CharSet.Auto)]
public static extern int SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);
[ DllImport("user32.dll" , CharSet = CharSet.Auto)]
public static extern IntPtr SendMessage(HandleRef hWnd, int msg, IntPtr wParam, IntPtr lParam);
[ DllImport("gdi32.dll" , CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true )]
public static extern bool BitBlt(HandleRef hDC, int x, int y, int nWidth, int nHeight, HandleRef hSrcDC, int xSrc, int ySrc, int dwRop);
/// <summary>
/// 支持呈现到指定的位图。
/// </summary>
public static Bitmap DrawToBitmap( Control control, Bitmap bitmap, Rectangle targetBounds)
{
if (bitmap == null )
{
throw new ArgumentNullException( "bitmap");
}
if (((targetBounds.Width <= 0) || (targetBounds.Height <= 0)) || ((targetBounds.X < 0) || (targetBounds.Y < 0)))
{
throw new ArgumentException( "targetBounds");
}
Bitmap image = new Bitmap(control.Width, control.Height, bitmap.PixelFormat);
using (Graphics graphics = Graphics.FromImage(image))
{
IntPtr hdc = graphics.GetHdc();
SendMessage( new HandleRef (control, control.Handle), 0x317, hdc, (IntPtr)30);
using (Graphics graphics2 = Graphics.FromImage(bitmap))
{
IntPtr handle = graphics2.GetHdc();
BitBlt( new HandleRef (graphics2, handle), 0, 0, control.Width, control.Height, new HandleRef(graphics, hdc), targetBounds.X, targetBounds.Y,
0xcc0020);
graphics2.ReleaseHdcInternal(handle);
}
graphics.ReleaseHdcInternal(hdc);
}
return image;
}
- 用JavaScript将Canvas内容转化成图片的方法
上周我们花了半天时间开发下一个准备放进Mozilla Marketplace的应用.有一个应用现在非常的火热,那就是Instagram,Facebook花了100万美元收购了它.我们也想有100万美元 ...
- 个人永久性免费-Excel催化剂功能第54波-批量图片导出,调整大小等
图片作为一种数据存在,较一般的存放在Excel单元格或其他形式存在的文本数据,对其管理更为不易,特别是仅有Excel原生的简单的插入图片功能时,Excel催化剂已全面覆盖图片数据的使用场景,无论是图片 ...
- 修改css的(屏蔽)overflow: hidden;实现浏览器能把网页全图保存成图片
摘要: 1.项目需要,需要对网页内容“下载”保存成全图片 2.QQ浏览器等主流浏览器都支持这种下载保存功能 3.项目需要场景:编写好的项目维护文档,放在服务器上.如果是txt不能带图片可视化,如果wo ...
- Android:将View的内容映射成Bitmap转图片导出
前段时间在网上看到这么个例子是将view映射到一个bitmap中,稍加改进可以用于一些截图工具或者截图软件(QQ截图之类),例子写的不够完善,不过很有些学习的意义内容大致如下: 在Android中自有 ...
- 同步手绘板——将View的内容映射成Bitmap转图片导出
在Android中自有获取view中的cache内容,然后将内容转换成bitmap,方法名是:getDrawingCache(),返回结果为Bitmap,但是刚开始使用的时候,得到的结果都是null, ...
- Enterprise Architect 13 : 将绘制的图形导出成图片 或者 拷贝到剪贴板中
使用Enterprise Architect 13 工具画类图.包图.需求图.状态图.时序图什么的导出成图片格式 或者拷贝到剪贴版,步骤如下: Publish -> Save Image -&g ...
- 前端借助dom-to-image把HTML转成图片并通过ajax上传到服务器
之前接到了一个任务,把jsp中的table转成一个图片,保存在指定文件夹并显示在前端. 我的思路是:一.引用第三方js在前端把table转成图片 二.通过ajax把图片上传到服务器,保存在指定文件夹 ...
- 关于View转化成bitmap保存成图片
产品今天说项目分享时要分享出一张 封面图片 + 几行文字 + 二维码图片 的图片. 思索了一下 封面图片和二维码图片让后台给接口得到地址, 主要还是找个方式得到一个包含这些内容的图片.于是就想能不能 ...
- OpenFlashChart的图片导出
http://www.cnblogs.com/mcmurphy/archive/2012/10/15/2724894.html http://teethgrinder.co.uk/open-flash ...
随机推荐
- 《利用python进行数据分析》读书笔记--第六章 数据加载、存储与文件格式
http://www.cnblogs.com/batteryhp/p/5021858.html 输入输出一般分为下面几类:读取文本文件和其他更高效的磁盘存储格式,加载数据库中的数据.利用Web API ...
- pure virtual function call
2015-04-08 10:58:19 基类中定义了纯虚函数,派生类中将其实现. 如果在基类的构造函数或者析构函数中调用了改纯虚函数, 则会出现R6205 Error: pure virtual fu ...
- sqoop的使用
1.sqoop的安装 1.1 与hadoop和hive的集成,修改/opt/cdh/sqoop-1.4.5-cdh5.3.6/conf/sqoop-env.sh 文件
- 刘子健的第二次博客——有关CCCCC语言(・᷄ᵌ・᷅)
刘子健的第二次博客--有关CCCCC语言(・᷄ᵌ・᷅) 下面又到了回答老师问题的时候啦-(・᷄ᵌ・᷅) 有些问题正在深思熟虑中!敬请期待近期的不间断更新! 你有什么技能比大多人(超过90%以上)更好? ...
- ubuntu gtk2.0 一个简单完整的窗口
//gtk_main();开了线程,关闭窗口并不能退出程序,需要手动添加 //gtk2.0,window quit compelete example #include <gtk/gtk.h&g ...
- CVE-2016-4758: UXSS in Safari's showModalDialog
I would like to share about details of Safari's UXSS bug(CVE-2016-4758). This bug was fixed in Safar ...
- SQL函数
1,字符串截取拼接 CONCAT(),'****');SUBSTRING_INDEX(c.context,'}',1);SUBSTRING_INDEX(a.task_context,':',-1) a ...
- 部署wcf到IIS时的问题
1,部署到IIS后,在浏览器可以访问.但客户端添加服务引用时,出现错误: - 下载“http://admin-pc/IISHostService/Service1.svc?xsd=xsd0”时出错.- ...
- 增量处理属性之记录模式(Record Modes)
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- nancy中视图呈现 Html.Partial(RenderPage的替代品)
在mvc中有RenderPage 用来呈现其他视图的内容,而在nancy中没有RenderPage.怎么办呢? mvc中RenderPage的替代品,就是 Html.Partial. 使用方式 @Ht ...