今天一位同事想寫一個全屏幕截圖的代碼
int width = Screen
int height = Screen
Bitmap bmp = new Bitmap(width
using (Graphics g = Graphics
g
}
public partial class FullScreenForm : Form {
private Rectangle rectSelected = Rectangle
private bool isClipping = false;
private Bitmap screen;
private Bitmap coverLayer = null;
private Color coverColor;
private Brush rectBrush = null;
private Bitmap resultBmp = null;
public FullScreenForm(Bitmap screen) {
InitializeComponent();
int width = Screen
int height = Screen
coverLayer = new Bitmap(width
coverColor = Color
rectBrush = new SolidBrush(coverColor);
using (Graphics g = Graphics
g
}
this
this
this
}
protected override void OnMouseDown(MouseEventArgs e) {
if (e
isClipping = true;
rectSelected
}
else if (e
this
}
}
protected override void OnMouseMove(MouseEventArgs e) {
if (e
rectSelected
rectSelected
this
}
}
protected override void OnMouseUp(MouseEventArgs e) {
if (e
rectSelected
rectSelected
this
resultBmp = new Bitmap(rectSelected
using (Graphics g = Graphics
g
}
this
}
}
protected override void OnPaint(PaintEventArgs e) {
Graphics g = e
g
g
PaintRectangle();
}
protected override void OnPaintBackground(PaintEventArgs e) {
}
protected override void OnKeyDown(KeyEventArgs e) {
if (e
this
}
}
private void PaintRectangle() {
using (Graphics g = Graphics
g
GraphicsPath path = new GraphicsPath();
path
path
g
g
}
}
public Bitmap ResultBitmap {
get { return resultBmp; }
}
}
上面的代碼都很容易看明白
From:http://tw.wingwit.com/Article/program/net/201311/12191.html