2007-01-05

C#模仿QQ截图功能

来源: CSDN 作者:往事随风 评论 0 条
 
imgformat = System.Drawing.Imaging.ImageFormat.Jpeg;
}

if(isSave)
{
try
{
CaptureScreenForm.image.Save(fileName,imgformat);
MessageBox.Show("图片已经成功保存!~~");
}
catch
{
MessageBox.Show("保存失败,你还没有截取过图片或已经清空图片!");
}
}

}

}
}

private void fullScreenBtn_Click(object sender, System.EventArgs e)
{
CaptureScreenForm.image = windowFullScreen();
picbox.Image = CaptureScreenForm.image;
}

public static Bitmap windowFullScreen()
{
//建立屏幕Graphics
Graphics grpScreen = Graphics.FromHwnd(IntPtr.Zero);
//根据屏幕大小建立位图
Bitmap bitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width,Screen.PrimaryScreen.Bounds.Height,grpScreen);
//建立位图相关Graphics
Graphics grpBitmap = Graphics.FromImage(bitmap);
//建立屏幕上下文
IntPtr hdcScreen = grpScreen.GetHdc();
//建立位图上下文
IntPtr hdcBitmap = grpBitmap.GetHdc();
//将屏幕捕捉保存在图位中
BitBlt(hdcBitmap,0,0,bitmap.Width,bitmap.Height,hdcScreen,0,0,0x00CC0020);
//关闭位图句柄
grpBitmap.ReleaseHdc(hdcBitmap);
//关闭屏幕句柄
grpScreen.ReleaseHdc(hdcScreen);
//释放位图对像
grpBitmap.Dispose();
//释放屏幕对像
grpScreen.Dispose();

//返回捕捉位图
return bitmap;
}

private void mouseCaptureBtn_Click(object sender, System.EventArgs e)
{
MouseCaptureForm mouseCapture = new MouseCaptureForm();
mouseCapture.Show();
}
}
}

另一个截屏文件:

MouseCaptureForm.cs

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace CaptureScreen
{
/// <summary>
/// MouseCaptureForm 的摘要说明。
/// </summary>
public class MouseCaptureForm : System.Windows.Forms.Form
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
//
//自定义变量
//
private Point pot;
private Rectangle area = Rectangle.Empty;
private Image img;
private int index = -1;
private string noselectString = "\n.请按下鼠标左键不放拖动选取截图区域\n\n .单击鼠标右键或按ESC取消截图";
private string selectingString = "\n.松开鼠标左键确定选取范围\n\n.按ESC重新选择";
private string selectedString = "\n.按鼠标左键调整选择范围\n\n .双击鼠标左键保存截图 \n\n.按鼠标右键重新选择 \n\n.ESC键取消截图";
private System.Windows.Forms.Label tiptext;

//
//系统生成定义
//
private System.ComponentModel.Container components = null;

public MouseCaptureForm()
共8页: 上一页 [1] [2] [3] 4 [5] [6] [7] [8] 下一页

(本文仅表明作者个人观点,不代表本站及其管理员立场.) 推荐 收藏 投稿 打印 返回 关闭
上一篇:Java应用web开发备用工具  
下一篇:详细讲述Java中的克隆
    评论加载中…
 推荐文章
     

网站首页  -  网站地图 -   站长论坛  -  网站投稿  -    -  网站管理
Copyright © 2008 芜湖站长站 All Rights Reserved 皖ICP备07500611号