c#截屏
各位大侠谁有c#用鼠标截取屏幕的代码呀,急救呀vs2005 --------------------编程问答-------------------- 我这里有一个,你要的话加QQ,546596542 提示:QQ截屏 --------------------编程问答-------------------- C#模拟QQ截屏功能http://www.cnblogs.com/tuyile006/archive/2007/07/16/815843.html
可以利用Graphics类的CopyFromScreen方法来实现屏幕截取,舍弃了比较麻烦的API函数,只要几句代码就能实现了,而且这个这个方法能实现只抓取部分区域的屏幕,可以实现类似qq抓屏的功能。
仿QQ的屏幕截图 也是另外一篇GDI+绘图处理文章。还有源代码下载。不错。我也下载研究过了。
http://www.cnblogs.com/zhouyinhui/archive/2006/06/27/437017.html
一个全屏的背景窗口,其以整个屏幕图像为背景图片;
一个取景窗口(红色矩形),在背景窗口拖动鼠标时可以改变该取景窗口的大小,形成区域的选定效果。
双击取景窗口时将对应的图像复制到剪切板。
--------------------编程问答-------------------- 不懂,up --------------------编程问答-------------------- 菜鸟来看看,丿丿 --------------------编程问答-------------------- 帮顶 --------------------编程问答--------------------
public static void copyscreen()
{
Rectangle rec = Screen.PrimaryScreen.Bounds;
Image img = new Bitmap(rec.Width, rec.Height);
Graphics g = Graphics.FromImage(img);
g.CopyFromScreen(rec.Location, new Point(0, 0), rec.Size);
Clipboard.SetDataObject(img, false);
}
--------------------编程问答-------------------- g.CopyFromScreen(rec.Location, new Point(0, 0), rec.Size);
把rec.Location改成你鼠标的mousedown
rec.Size改成mouseup后两坐标形成的矩形 --------------------编程问答-------------------- 菜鸟来看看 --------------------编程问答-------------------- mark --------------------编程问答-------------------- 来看看 --------------------编程问答-------------------- ding --------------------编程问答-------------------- 收藏 --------------------编程问答-------------------- http://www.cnblogs.com/tuyile006/archive/2007/07/16/815843.html
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace copyScreen
{
public partial class ScreenForm : Form
{
public ScreenForm()
{
InitializeComponent();
}
public event copyToFatherTextBox copytoFather; //截屏完毕后交个父窗体处理截图
public bool begin = false; //是否开始截屏
public bool isDoubleClick = false;
public Point firstPoint = new Point(0, 0); //鼠标第一点
public Point secondPoint = new Point(0, 0); //鼠标第二点
public Image cachImage = null; //用来缓存截获的屏幕
public int halfWidth = 0;//保存屏幕一半的宽度
public int halfHeight = 0;//保存屏幕一般的高度
/*复制整个屏幕,并让窗体填充屏幕*/
public void copyScreen()
{
Rectangle r = Screen.PrimaryScreen.Bounds;
Image img = new Bitmap(r.Width, r.Height);
Graphics g = Graphics.FromImage(img);
g.CopyFromScreen(new Point(0, 0), new Point(0, 0), r.Size);
//窗体最大化,及相关处理
this.Width = r.Width;
this.Height = r.Height;
this.Left = 0;
this.Top = 0;
pictureBox1.Width = r.Width;
pictureBox1.Height = r.Height;
pictureBox1.BackgroundImage = img;
cachImage = img;
halfWidth = r.Width / 2;
halfHeight = r.Height / 2;
this.Cursor = new Cursor(GetType(), "MyCursor.cur");
}
private void ScreenForm_Load(object sender, EventArgs e)
{
copyScreen();
}
/*鼠标按下时开始截图*/
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if(!isDoubleClick)
{
begin = true;
firstPoint = new Point(e.X, e.Y);
changePoint(e.X, e.Y);
msg.Visible = true;
}
}
/*鼠标移动时显示截取区域的边框*/
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (begin)
{
//获取新的右下角坐标
secondPoint = new Point(e.X, e.Y);
int minX = Math.Min(firstPoint.X, secondPoint.X);
int minY = Math.Min(firstPoint.Y, secondPoint.Y);
int maxX = Math.Max(firstPoint.X, secondPoint.X);
int maxY = Math.Max(firstPoint.Y, secondPoint.Y);
//重新画背景图
Image tempimage = new Bitmap(cachImage);
Graphics g = Graphics.FromImage(tempimage);
//画裁剪框
g.DrawRectangle(new Pen(Color.Red),minX,minY,maxX-minX,maxY-minY);
pictureBox1.Image = tempimage;
//计算坐标信息
msg.Text = "左上角坐标:(" + minX.ToString() + "," + minY.ToString() + ")\r\n";
msg.Text += "右下角坐标:(" + maxX.ToString() + "," + maxY.ToString() + ")\r\n";
msg.Text += "截图大小:" + (maxX - minX) + "×" + (maxY - minY) + "\r\n";
msg.Text += "双击任意地方结束截屏!";
changePoint((minX + maxX) / 2, (minY + maxY) / 2);
}
}
/*动态调整显示信息的位置,输入参数为当前截屏鼠标位置*/
public void changePoint(int x, int y)
{
if (x < halfWidth)
{
if (y < halfHeight)
{ msg.Top = halfHeight; msg.Left = halfWidth; }
else
{ msg.Top = 0; msg.Left = halfWidth; }
}
else
{
if (y < halfHeight)
{ msg.Top = halfHeight; msg.Left = 0; }
else
{ msg.Top = 0; msg.Left = 0; }
}
}
/*鼠标放开时截图操作完成*/
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
begin = false;
isDoubleClick = true; //之后再点击就是双击事件了
}
/*双击时截图时,通知父窗体完成截图操作,同时关闭本窗体*/
private void pictureBox1_DoubleClick(object sender, EventArgs e)
{
if (firstPoint != secondPoint)
{
int minX = Math.Min(firstPoint.X, secondPoint.X);
int minY = Math.Min(firstPoint.Y, secondPoint.Y);
int maxX = Math.Max(firstPoint.X, secondPoint.X);
int maxY = Math.Max(firstPoint.Y, secondPoint.Y);
Rectangle r = new Rectangle(minX, minY, maxX - minX, maxY - minY);
copytoFather(r);
}
this.Close();
//msg.Text = r.ToString();
}
}
}
界面如下:
--------------------编程问答-------------------- 不懂,但来顶一下! --------------------编程问答-------------------- 我顶 --------------------编程问答-------------------- 学习一下 --------------------编程问答-------------------- 好东西当然不会放过
学习ing --------------------编程问答-------------------- 楼主 你可以参考下13楼留下的博客地址。
--------------------编程问答-------------------- http://www.cnblogs.com/tuyile006/archive/2007/07/16/815843.html --------------------编程问答-------------------- mark --------------------编程问答-------------------- 找技术人员问去 --------------------编程问答-------------------- GDI+
CopyFromScreen --------------------编程问答-------------------- 这个也是,.. 你可以参考下
http://blog.csdn.net/zgke/archive/2009/03/04/3956936.aspx --------------------编程问答-------------------- 多多学习一下。顶!! --------------------编程问答-------------------- 可以调用api实现啊 --------------------编程问答-------------------- 参考参考 --------------------编程问答-------------------- 声明的
public event copyToFatherTextBox copytoFather;
是什么? --------------------编程问答-------------------- 13楼的厉害
学习
--------------------编程问答-------------------- up --------------------编程问答-------------------- 回帖是一种美德!每天回帖即可获得 10 分可用分! --------------------编程问答-------------------- 我有程序,和13楼的差不多。可以发到你邮箱
--------------------编程问答-------------------- 网上有的好好收收,好多呢。耐心 --------------------编程问答-------------------- 好东西 --------------------编程问答-------------------- Good --------------------编程问答-------------------- 2楼的代码:
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
//获得当前屏幕的分辨率
Screen scr = Screen.PrimaryScreen;
Rectangle rc = scr.Bounds;
int iWidth = rc.Width;
int iHeight = rc.Height;
//创建一个和屏幕一样大的Bitmap
Image myImage = new Bitmap(iWidth, iHeight);
//从一个继承自Image类的对象中创建Graphics对象
Graphics g = Graphics.FromImage(myImage);
//抓屏并拷贝到myimage里
g.CopyFromScreen(new Point(0, 0), new Point(0, 0), new Size(iWidth, iHeight));
//保存为文件
myImage.Save(@"c:/1.jpeg");
}
}
}
可以实现。 --------------------编程问答-------------------- --------------------编程问答-------------------- 看看 --------------------编程问答-------------------- up --------------------编程问答--------------------
http://www.cnblogs.com/tuyile006/archive/2007/07/16/815843.html--------------------编程问答-------------------- 真是高手如云啊!顶 --------------------编程问答-------------------- UP --------------------编程问答-------------------- good --------------------编程问答-------------------- 学习一下!!! --------------------编程问答-------------------- 看来分我要了。
最近做的项目中,恰好设计了这个功能。
看好。
关于鼠标移动获取要截取的区域,就不用写代码了吧?
只要确定了起始和结束点,以及截取的矩形,调用下面的这个函数就行了。返回截取的图像。
/// <summary>
/// 抓屏函数
/// </summary>
/// <param name="SourcePoint">起始点</param>
/// <param name="DestinationPoint">目标点</param>
/// <param name="SelectionRectangle">要画的区域</param>
/// <returns></returns>
public static Bitmap CaptureScreen(Point SourcePoint, Point DestinationPoint, Rectangle SelectionRectangle)
{
Bitmap bitmap = new Bitmap(SelectionRectangle.Width, SelectionRectangle.Height);
Graphics g = Graphics.FromImage(bitmap);
g.CopyFromScreen(SourcePoint, DestinationPoint, SelectionRectangle.Size);
return bitmap;
} --------------------编程问答-------------------- 长见识了! --------------------编程问答-------------------- 长长见识也不错 --------------------编程问答-------------------- 学习 --------------------编程问答-------------------- ASP.NET(C#)技术联盟高级群,欢迎工作中的朋友进来一起探讨并解决工作中遇到的问题!一群37078937(已满)二群37078867三群37078820(欢迎上海地区的朋友并爱好Dota的)
严禁加多群,群定期清理长期不发言不讨论的朋友,请多包涵。 --------------------编程问答-------------------- 学习中!!! --------------------编程问答-------------------- up --------------------编程问答-------------------- 帮顶!! --------------------编程问答-------------------- --------------------编程问答-------------------- SendKeys("{xxx}"); --------------------编程问答-------------------- 2.0已经有函数了
--------------------编程问答-------------------- http://download.csdn.net/source/1487838
这个是截图的实例 下载下 绝对超值! --------------------编程问答-------------------- ding --------------------编程问答-------------------- 看看。。。。 --------------------编程问答-------------------- 怎么没看见结贴?
--------------------编程问答--------------------
bu cuo --------------------编程问答-------------------- 回帖是一种美德!每天回帖即可获得 10 分可用分!
学习学习! --------------------编程问答-------------------- 我是来学习的! --------------------编程问答-------------------- 收获不小哦,今天逛一天...值 --------------------编程问答-------------------- very Good!
补充:.NET技术 , 其他语言