2014-01-10 17 views
1

我想畫一個像十字或其他東西的漂亮的「指示器」,以確切知道在屏幕放大鏡中放置鼠標的位置,在像素周圍繪製交叉指示器。在這個屏幕放大鏡上畫一個漂亮的交叉指示器?

不幸的是我的GDI +知識不好。

這是它的外觀放大鏡窗口:

enter image description here

而且我想提醒像一個指標,目前mousecursor或像這樣的交叉指標(但這是太醜陋有任何像素precission因爲我已經使用MSPAINT)

enter image description here

有人可以幫助我做到這一點?

這是我如何繪製圖像:

''' <summary> 
''' Repaints the Magnifier. 
''' </summary> 
Private Sub Repaint() 

    ' Region Length. 
    Dim lengthX As Single = Me.Width * ZoomFactor 
    Dim lengthY As Single = (Me.Height - ZoomFactor_KryptonTrackBar.Bounds.Height) * ZoomFactor 

    ' Center Image Around The Mouse. 
    Dim offsetX As Single = (Me.Width * ZoomFactor) \ 2 
    Dim offsetY As Single = (Me.Height * ZoomFactor) \ 2 

    ' Actual Area To Blit To. 
    Dim blitAreaX As Integer = Me.Width 
    Dim blitAreaY As Integer = Me.Height - ZoomFactor_KryptonTrackBar.Bounds.Height 

    bmp = New Bitmap(CInt(blitAreaX), CInt(blitAreaY)) 
    g1 = ZoomFactor_PictureBox.CreateGraphics 
    g2 = Graphics.FromImage(bmp) 

    ' Set the image quality. 
    g1.SmoothingMode = SmoothingMode.None 
    g1.CompositingQuality = CompositingQuality.HighSpeed 
    g1.PixelOffsetMode = PixelOffsetMode.HighSpeed 
    g1.InterpolationMode = InterpolationMode.NearestNeighbor 

    g2.SmoothingMode = SmoothingMode.None 
    g2.CompositingQuality = CompositingQuality.HighSpeed 
    g2.PixelOffsetMode = PixelOffsetMode.HighSpeed 
    g2.InterpolationMode = InterpolationMode.NearestNeighbor 

    ' Devicecontext (DC) of the Desktop and the Graphics object. 
    Dim hWndWindow As IntPtr = GetDesktopWindow() 
    Dim hdcWindow As IntPtr = GetDC(hWndWindow) 
    Dim hdcGraphics As IntPtr = g2.GetHdc() 

    ' BitBlt the Screen (Captures Transparent Windows & Prevents Mirror Effect) 
    BitBlt(hdcGraphics.ToInt32, 0, 0, blitAreaX, blitAreaY, 
      hdcWindow.ToInt32, MousePosition.X - offsetX, MousePosition.Y - offsetY, 
      TernaryRasterOperations.SRCCOPY Or 
      TernaryRasterOperations.CAPTUREBLT Or 
      TernaryRasterOperations.NOMIRRORBITMAP) 

    ' Free Memory 
    ReleaseDC(hWndWindow, hdcWindow) 
    g2.ReleaseHdc(hdcGraphics) 

    ' Paint 
    g1.DrawImage(bmp, New Rectangle(0, 0, blitAreaX, blitAreaY), 0, 0, lengthX, lengthY, GraphicsUnit.Pixel) 

    ' Set Magnifier position. 
    ' Do this after painting to reduce blinking effects. 
    SetMangifierPosition() 

End Sub 

更新

我已經做了修改,以繪製默認十字鼠標光標,但它不是正確神韻:我不知道爲什麼會發生這種情況,因爲我已將劃分圖像的一半控制大小除以位圖中的光標位置:

注意:但是,如果我放大100%那麼我可以注意到光標仍然沒有被分配,但它正在向正確的像素傾斜,我不明白這一點。

... 
    ' Paint 
    g1.DrawImage(bmp, New Rectangle(0, 0, blitAreaX, blitAreaY), 0, 0, lengthX, lengthY, GraphicsUnit.Pixel) 
... 

    ' And paint the mouse cursor 
    Cursors.Cross.Draw(g1, New Rectangle(ZoomFactor_PictureBox.Width \ 2, ZoomFactor_PictureBox.Height \ 2, 0, 0)) 

enter image description here

更新2

解決:

enter image description here

' Paint 
    g1.DrawImage(bmp, New Rectangle(0, 0, blitAreaX, blitAreaY), 0, 0, lengthX, lengthY, GraphicsUnit.Pixel) 

    ' Set the cursor Rectangle. 
    Dim CursorRect As New Rectangle With 
    { 
    .Size = New Size(0, 0), 
    .Location = New Point((ZoomFactor_PictureBox.Width \ 2) - Cursors.Cross.Size.Width \ 2, 
          (ZoomFactor_PictureBox.Height \ 2) - Cursors.Cross.Size.Height \ 2 - 10) 
    } 

    ' Paint the mouse cursor 
    Cursors.Cross.Draw(g1, CursorRect) 

回答

相關問題