private void snapshot_mouse_move(object sender, MouseEventArgs e)
{
int magnification = 4;//倍率,调节放大倍数,可由TrackBar控制调节
const int imgWidth = 160;//放大后图片的宽度
const int imgHeight = 160;//放大后图片的高度
DateTime dateTime = DateTime.Now;
TimeSpan ts = dateTime - currentTime;
if (ts.TotalMilliseconds > 1000 / 60)//60帧最高采集率
{
int index = int.Parse((string)((PictureBox)sender).Tag);
//对图像进行放大显示
Bitmap bt = new Bitmap(imgWidth / magnification, imgHeight / magnification);
Graphics g = Graphics.FromImage(bt);
g.CopyFromScreen(
new Point(Cursor.Position.X - imgWidth / (2 * magnification),
Cursor.Position.Y - imgHeight / (2 * magnification)),
new Point(0, 0),
new Size(imgWidth / magnification, imgHeight / magnification));
IntPtr dc1 = g.GetHdc();
g.ReleaseHdc(dc1);
this.Cursor = new Cursor((new Bitmap(bt, imgWidth, imgHeight)).GetHicon());
currentTime = dateTime;
}
}
private void snapshot_mouse_leave(object sender, EventArgs e)
{
this.Cursor = Cursors.Default;
}
C# 鼠标跟随放大镜
最新推荐文章于 2024-04-14 01:41:03 发布