/// 将容器内容转成图片导出,这里的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 ...
随机推荐
- 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror) in codeforces(codeforces730)
A.Toda 2 思路:可以有二分来得到最后的数值,然后每次排序去掉最大的两个,或者3个(奇数时). /************************************************ ...
- android studio卡死问题
今天重新安装android studio 的时候 建工程的时候尽然卡住了,卡在 第一次卡在了 Refreshing gradle project 第二次卡 gradle:download http:/ ...
- java(2)之前往对象村
这次说一说面向对象与面向过程的区别以及面向对象的优点.
- FMDB
一.FMDB简介 1.FMDB简介 iOS中原生的SQLite API在进行数据存储的时候,需要使用C语言中的函数,操作比较繁琐.于是,就出现了一系列将SQLite API进行封装的库,例如FMDB. ...
- ImageList图标左边有黑色竖线
ImageList图标左边有黑色竖线, 原因 ImageList颜色深度太小引起的,解决方案,把颜色深度调成Depth32Bit 默认: 修改为: 结果: 备注:根据文件获得文件的系统图标: Icon ...
- python列表、元祖、字典
python列表 ['a','1','vs2'] 里面的值可以改 python元祖 ('a','1','css','sdf12') 里面的值不能改 python字典 {'s ...
- 24.Redis2.8主从集群sentinel
0.集群架构(此处只说两种;本文2种,避免sentinel成为单节点) 第一种: 第二种: 1.下载redis2.8.x版本,2.8.x都是稳定版 redis-2.8.24.tar.gz 2.解压,安 ...
- Sublime相关
通过添加 Build System 的方式来使 Sublime Text 3 运行 JS.ES6: 参考文章:如何优雅地使用Sublime Text3 参考书目:<ES6标准入门>阮一峰 ...
- NPOI的使用Excel模板导出
private string ExportScMeeting(DataTable source) { string templateFile = Server.MapPath(@"Excel ...
- iOS开发 获取状态栏的点击事件
首先我们追踪UIStatusBar的触摸事件,需要在AppDelegate里面加入以下代码 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEve ...