[英]How to make a simple magnifier in C#
I followed the following in post on "Creating a screen magnifier" .我在“创建屏幕放大镜”的帖子中遵循了以下内容。
Therefore I have this code.因此我有这个代码。 It is not copy & pasted from the post.它不是从帖子中复制和粘贴的。 I have also added a timer so the form is not blank.我还添加了一个计时器,因此表单不是空白的。 However I have found some problems.但是我发现了一些问题。
Here is the code I have got now.这是我现在得到的代码。
Graphics g;
Bitmap bmp;
private void Timer1_Tick(object sender, EventArgs e)
{
bmp = new Bitmap(250, 200);
g = this.CreateGraphics();
g = Graphics.FromImage(bmp);
g.CopyFromScreen(MousePosition.X , MousePosition.Y , 0, 0, new Size(300, 300));
pictureBox1.Image = bmp;
}
The results seem to be exactly the same to this software that I found during my research.结果似乎与我在研究期间发现的这个软件完全相同。 the link , It takes you to a Japanese webpage.链接,它会将您带到一个日语网页。
You're going to have to play around with the various numbers in the example in order to see what effect they have on the output.您将不得不处理示例中的各种数字,以查看它们对输出的影响。 It'll help to turn them into variables so you can play with them more easily.将它们转换为变量会有所帮助,这样您就可以更轻松地使用它们。 Here is a good start, no promises that it works, but it'll give you a good place to start experimenting until you get what you want.这是一个良好的开端,不保证它有效,但它会给你一个开始试验的好地方,直到你得到你想要的东西。
Graphics g;
Bitmap bmp;
private void Timer1_Tick(object sender, EventArgs e)
{
var endWidth = 300;
var endHeight = 300;
var scaleFactor = 2; //perhaps get this value from a const, or an on screen slider
var startWidth = endWidth / scaleFactor;
var startHeight = endHeight / scaleFactor;
bmp = new Bitmap(startWidth, startHeight);
g = this.CreateGraphics();
g = Graphics.FromImage(bmp);
var xPos = Math.Max(0, MousePosition.X - (startWidth/2)); // divide by two in order to center
var yPos = Math.Max(0, MousePosition.Y - (startHeight/2));
g.CopyFromScreen(xPos, yPos, 0, 0, new Size(endWidth, endWidth));
pictureBox1.Image = bmp;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.