获取部分,我的抓屏是简单的VB.NEt代码,自己改写 Dim CurImage As Image = New Bitmap(DrawRectangle.Width, DrawRectangle.Height) Dim g As Graphics = Graphics.FromImage(CurImage) Dim FromRectangle As Rectangle Dim ToRectangle As Rectangle '=========================================== FromRectangle = New Rectangle(DrawRectangle.X, DrawRectangle.Y, DrawRectangle.Width, DrawRectangle.Height) ToRectangle = New Rectangle(0, 0, DrawRectangle.Width, DrawRectangle.Height) g.Clear(Color.White) 'PicBox.Image, ToRectangle, FromRectangle '分别是:截取可能和目标图形不是一样大 '原有图形,目标图形的区域<就是在你设定的图形里面的位置>,原有图形的区域 g.DrawImage(PicBox.Image, ToRectangle, FromRectangle, GraphicsUnit.Pixel) My.Computer.Clipboard.SetImage(CurImage)================================================================== 博客空间:http://blog.csdn.net/lovingkiss 资源下载:http://download.csdn.net/user/lovingkiss Email:loving-kiss@163.com 优惠接单开发,收费带初学者,组件控件定制开发,成品源代码批发 联系方式:Q64180940(请清楚注明业务还是技术咨询) 全天在线 ==================================================================
TO:lovingkiss(桃花影落飞神贱,碧海潮生<吹>玉箫 坦白从良 抗拒强奸)
建立一个可移动的矩形选框这部分能给出简单点的代码吗?那个没看明白,谢谢!!!
参考下这个代码试试:public partial class Form2 : Form { private Rectangle m_Rect; private Point m_LastMsPoint; private Point m_LastRectPoint; private bool m_CanMove; public Form2() { InitializeComponent(); m_Rect = new Rectangle(10, 10, 100, 80); } private void panel1_Paint(object sender, PaintEventArgs e) { e.Graphics.DrawRectangle(SystemPens.HotTrack, this.m_Rect); } private void panel1_MouseMove(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left && m_CanMove) { int x = m_LastRectPoint.X + e.X - this.m_LastMsPoint.X; int y = m_LastRectPoint.Y + e.Y - this.m_LastMsPoint.Y; this.m_Rect.Location = new Point(x, y); this.panel1.Invalidate(); this.panel2.Invalidate(); } } private void panel1_MouseDown(object sender, MouseEventArgs e) { m_LastMsPoint = e.Location; m_LastRectPoint = m_Rect.Location; m_CanMove = this.m_Rect.Contains(e.Location); } private void panel2_Paint(object sender, PaintEventArgs e) { Rectangle rect = new Rectangle(0, 0, this.m_Rect.Width, this.m_Rect.Height); e.Graphics.DrawImage(this.panel1.BackgroundImage, rect, this.m_Rect, GraphicsUnit.Pixel); } }
图片部分可以参考:Drawtools
绘制图形并可以拖动调整
http://www.codeproject.com/csharp/drawtools.asp
增强型Drawtools
可以插入图片....
http://www.codeproject.com/useritems/DrawToolsRedux.asp
Dim g As Graphics = Graphics.FromImage(CurImage)
Dim FromRectangle As Rectangle
Dim ToRectangle As Rectangle
'===========================================
FromRectangle = New Rectangle(DrawRectangle.X, DrawRectangle.Y, DrawRectangle.Width, DrawRectangle.Height)
ToRectangle = New Rectangle(0, 0, DrawRectangle.Width, DrawRectangle.Height)
g.Clear(Color.White)
'PicBox.Image, ToRectangle, FromRectangle
'分别是:截取可能和目标图形不是一样大
'原有图形,目标图形的区域<就是在你设定的图形里面的位置>,原有图形的区域
g.DrawImage(PicBox.Image, ToRectangle, FromRectangle, GraphicsUnit.Pixel)
My.Computer.Clipboard.SetImage(CurImage)==================================================================
博客空间:http://blog.csdn.net/lovingkiss
资源下载:http://download.csdn.net/user/lovingkiss
Email:loving-kiss@163.com
优惠接单开发,收费带初学者,组件控件定制开发,成品源代码批发
联系方式:Q64180940(请清楚注明业务还是技术咨询) 全天在线
==================================================================
建立一个可移动的矩形选框这部分能给出简单点的代码吗?那个没看明白,谢谢!!!
{
private Rectangle m_Rect;
private Point m_LastMsPoint;
private Point m_LastRectPoint;
private bool m_CanMove;
public Form2()
{
InitializeComponent(); m_Rect = new Rectangle(10, 10, 100, 80);
} private void panel1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawRectangle(SystemPens.HotTrack, this.m_Rect);
} private void panel1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left && m_CanMove)
{
int x = m_LastRectPoint.X + e.X - this.m_LastMsPoint.X;
int y = m_LastRectPoint.Y + e.Y - this.m_LastMsPoint.Y;
this.m_Rect.Location = new Point(x, y);
this.panel1.Invalidate();
this.panel2.Invalidate();
}
} private void panel1_MouseDown(object sender, MouseEventArgs e)
{
m_LastMsPoint = e.Location;
m_LastRectPoint = m_Rect.Location;
m_CanMove = this.m_Rect.Contains(e.Location);
} private void panel2_Paint(object sender, PaintEventArgs e)
{
Rectangle rect = new Rectangle(0, 0, this.m_Rect.Width, this.m_Rect.Height);
e.Graphics.DrawImage(this.panel1.BackgroundImage, rect, this.m_Rect, GraphicsUnit.Pixel);
}
}