[英]How to make a simple magnifier in C#
我在“創建屏幕放大鏡”的帖子中遵循了以下內容。
因此我有這個代碼。 它不是從帖子中復制和粘貼的。 我還添加了一個計時器,因此表單不是空白的。 但是我發現了一些問題。
這是我現在得到的代碼。
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;
}
結果似乎與我在研究期間發現的這個軟件完全相同。 鏈接,它會將您帶到一個日語網頁。
您將不得不處理示例中的各種數字,以查看它們對輸出的影響。 將它們轉換為變量會有所幫助,這樣您就可以更輕松地使用它們。 這是一個良好的開端,不保證它有效,但它會給你一個開始試驗的好地方,直到你得到你想要的東西。
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.