|
|
|
网站建设 |
c#抓屏技术
|
|
[ 来源:中联无限科技有限公司 发布日期:2011/3/9 10:08:32 ]
|
|
|
| 有会的朋友指导一下了哈
先是给大家一个类:
class ScreenShot
{
public static void CaptureImage(Point SourcePoint, Point DestinationPoint, Rectangle SelectionRectangle, string FilePath)
{
using (Bitmap bitmap = new Bitmap(SelectionRectangle.Width, SelectionRectangle.Height))
{
using (Graphics g = Graphics.FromImage(bitmap))
{
g.CopyFromScreen(SourcePoint, DestinationPoint, SelectionRectangle.Size);
}
bitmap.Save(FilePath, ImageFormat.Bmp);
}
}
}
所需添加引用如下:
using System;
using System.Drawing;
using System.Drawing.Imaging;
调用方法:
private void button1_Click(object sender, EventArgs e)
{
saveFileDialog1.DefaultExt = "bmp";
saveFileDialog1.Filter = "bmp files (*.bmp)|*.bmp";
saveFileDialog1.Title = "导出地图为...";
saveFileDialog1.ShowDialog();
if (saveFileDialog1.FileName.Length > 0)
{
ScreenPath = saveFileDialog1.FileName;
}
else
{
return;
}
this.Refresh();
//3个参数:获得控件所在屏幕坐标,目标坐标点为(0,0),获得控件大小。
ScreenShot.CaptureImage(axMapControl1.PointToScreen(Point.Empty), Point.Empty, new Rectangle(axMapControl1.Location, axMapControl1.Size), ScreenPath);
}
|
|
|
有会的朋友指导一下了哈
先是给大家一个类: class ScreenShot { public static void CaptureImage(Point SourcePoint, Point DestinationPoint, Rectangle SelectionRectangle, string FilePath) { using (Bitmap bitmap = new Bitmap(SelectionRectangle.Width, SelectionRectangle.Height)) { using (Graphics g = Graphics.FromImage(bitmap)) { g.CopyFromScreen(SourcePoint, DestinationPoint, SelectionRectangle.Size); } bitmap.Save(FilePath, ImageFormat.Bmp); } } } 所需添加引用如下: using System; using System.Drawing; using System.Drawing.Imaging; 调用方法: private void button1_Click(object sender, EventArgs e) { saveFileDialog1.DefaultExt = "bmp"; saveFileDialog1.Filter = "bmp files (*.bmp)|*.bmp"; saveFileDialog1.Title = "导出地图为..."; saveFileDialog1.ShowDialog(); if (saveFileDialog1.FileName.Length > 0) { ScreenPath = saveFileDialog1.FileName; } else { return; } this.Refresh(); //3个参数:获得控件所在屏幕坐标,目标坐标点为(0,0),获得控件大小。 ScreenShot.CaptureImage(axMapControl1.PointToScreen(Point.Empty), Point.Empty, new Rectangle(axMapControl1.Location, axMapControl1.Size), ScreenPath); }
中联无限科技公司提供专业的成都网站建设、成都网站设计、成都网站制作、成都网站推广。
上一篇:使用C#发送邮件
下一篇:.Net ajax检测用户名是否重复
|
|
相关网站建设 |
|
|
|
|