C# 实现截屏效果
来源:互联网 发布:怎么开通淘宝 编辑:程序博客网 时间:2024/06/11 19:46
/// <summary>
/// 第一个页面只需要一个按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnCutter_Click(object sender, EventArgs e)
{
Image img = new Bitmap(Screen.AllScreens[0].Bounds.Width, Screen.AllScreens[0].Bounds.Height);
Graphics g = Graphics.FromImage(img);
g.CopyFromScreen(new Point(0, 0), new Point(0, 0), Screen.AllScreens[0].Bounds.Size);
ScreenBody body = new ScreenBody();
body.BackgroundImage = img;
body.ShowDialog();
}
-----------------------------------------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Linq;
using System.Runtime.InteropServices;
using System.Drawing.Imaging;
/**
* 徐殿笼
* 2010-07-01
* 类似于QQ屏幕截图效果
* ***/
namespace ImagePrint
{
public partial class ScreenBody : Form
{
public ScreenBody()
{
InitializeComponent();
}
private Graphics MainPainter; //主画笔
private Pen pen; //就是笔咯
private bool isDowned; //判断鼠标是否按下
private bool RectReady; //矩形是否绘制完成
private Image baseImage; //基本图形(原来的画面)
private Rectangle Rect; //就是要保存的矩形
private Point downPoint; //鼠标按下的点
int tmpx;
int tmpy;
/// <summary>
/// 鼠标双击保存截图
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ScreenBody_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (((MouseEventArgs)e).Button == MouseButtons.Left && Rect.Contains(((MouseEventArgs)e).X, ((MouseEventArgs)e).Y))
{
SaveFileDialog savafil = new SaveFileDialog();
savafil.FileName = DateTime.Now.ToString("yyyyMMddhhmmss");//用时间创建图片名称
savafil.Filter = "Image Files(*.JPG;*.GIF)|*.JPG;*.GIF|All files(*.*)|*.*";
if (savafil.ShowDialog() == DialogResult.OK)
{
Image memory = new Bitmap(Rect.Width, Rect.Height);
Graphics g = Graphics.FromImage(memory);
g.CopyFromScreen(Rect.X + 1, Rect.Y + 1, 0, 0, Rect.Size);
Clipboard.SetImage(memory);
memory.Save(savafil.FileName);
this.Close();
}
}
}
/// <summary>
/// 按下鼠标产生的特效
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ScreenBody_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
isDowned = true;
if (RectReady == false)
{
Rect.X = e.X;
Rect.Y = e.Y;
downPoint = new Point(e.X, e.Y);
}
if (RectReady == true)
{
tmpx = e.X;
tmpy = e.Y;
}
}
if (e.Button == MouseButtons.Right)
{
if (RectReady != true)
{
this.Close();
return;
}
MainPainter.DrawImage(baseImage, 0, 0);
RectReady = false;
}
}
/// <summary>
/// 当鼠标松开后!
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ScreenBody_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
isDowned = false;
RectReady = true;
}
}
/// <summary>
/// 当鼠标移动时候,记录坐标
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ScreenBody_MouseMove(object sender, MouseEventArgs e)
{
if (RectReady == false)
{
if (isDowned == true)
{
Image New = DrawScreen((Image)baseImage.Clone(), e.X, e.Y);
MainPainter.DrawImage(New, 0, 0);
New.Dispose();
}
}
if (RectReady == true)
{
if (Rect.Contains(e.X, e.Y))
{
//this.Cursor = Cursors.Hand;
if (isDowned == true)
{
//和上一次的位置比较获取偏移量
Rect.X = Rect.X + e.X - tmpx;
Rect.Y = Rect.Y + e.Y - tmpy;
//记录现在的位置
tmpx = e.X;
tmpy = e.Y;
MoveRect((Image)baseImage.Clone(), Rect);
}
}
}
}
/// <summary>
/// 当页面加载时候
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ScreenBody_Load(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Maximized;
MainPainter = this.CreateGraphics();
pen = new Pen(Brushes.Blue);
isDowned = false;
baseImage = this.BackgroundImage;
Rect = new Rectangle();
RectReady = false;
}
/// <summary>
/// 根据坐标来记录截屏
/// </summary>
/// <param name="Painter"></param>
/// <param name="Mouse_x"></param>
/// <param name="Mouse_y"></param>
private void DrawRect(Graphics Painter, int Mouse_x, int Mouse_y)
{
int width = 0;
int heigth = 0;
if (Mouse_y < Rect.Y)
{
Rect.Y = Mouse_y;
heigth = downPoint.Y - Mouse_y;
}
else
{
heigth = Mouse_y - downPoint.Y;
}
if (Mouse_x < Rect.X)
{
Rect.X = Mouse_x;
width = downPoint.X - Mouse_x;
}
else
{
width = Mouse_x - downPoint.X;
}
Rect.Size = new Size(width, heigth);
Painter.DrawRectangle(pen, Rect);
}
private Image DrawScreen(Image back, int Mouse_x, int Mouse_y)
{
Graphics Painter = Graphics.FromImage(back);
DrawRect(Painter, Mouse_x, Mouse_y);
return back;
}
private void MoveRect(Image image, Rectangle Rect)
{
Graphics Painter = Graphics.FromImage(image);
Painter.DrawRectangle(pen, Rect.X, Rect.Y, Rect.Width, Rect.Height);
//DrawRects(Painter);
MainPainter.DrawImage(image, 0, 0);
image.Dispose();
}
}
}
- C# 实现截屏效果
- C#实现PDA划屏效果
- c#实现闪屏Splash效果示例
- C#实现毛玻璃效果
- 截屏效果实现
- c#实现控件拖动效果
- C#实现窗体渐变效果
- C#实现图片轮转效果
- C# 实现桌面图片飘浮效果
- C#实现跑马灯效果
- C#实现跑马灯效果 .
- C# 多线程实现ProgressBar效果
- c#实现按钮拖动效果
- C#窗口编程实现StepPage效果
- C# 调用SetROP2实现橡皮线效果
- C#实现窗体的淡入淡出效果
- c#键盘DELETE实现BACKSPACE效果
- C#实现浮雕效果显示图片
- 排序算法(转载)
- 查找问题的异常堆栈,堆栈跟踪中出现一个 UnhandledExceptionFilter
- Ubuntu下基于heartbeat的双机热备
- 连接远程数据库配置
- All about JAVA 读取配置文件的方法 (这里是config.properties)
- C# 实现截屏效果
- MyEclipse 内怎么样修改(复制)项目名
- SEO报价参考
- 八种地板材料的优劣比较
- 进度条,message
- SQL 连接 JOIN 例解。(左连接,右连接,全连接,内连接,交叉连接,自连接)
- 海量数据库的查询优化及分页算法方案
- Android中保存图片的两种方式
- jbpm 4.4 与 spring 集成