2013-12-21 1 views
1

저는 VB.NET에서 도구와 유사한 프로그램을 조금 만들었습니다. 사각형 영역이라면 원하는 모든 영역을 스크린 샷 할 수 있습니다. 화면에서 영역을 선택하고 이미지로 저장합니다. 쉽습니다.타원 안에있는 영역 만 스크린 샷하는 방법?

내 문제는 직사각형 (표준 직사각형 모양 영역)뿐만 아니라 타원을 선택/그리기 및 스크린 내부의 스크린 샷을 캡쳐 할 수 있기를 원합니다. 참조 아래 이미지 :

screenshot only the inside of the Ellipse. the rest can be transparent

이 달성 할 수있는 방법이나 내가 그 사용할 수있는 라이브러리가 있습니까?

Public Class Form3 
    Private _bRubberBandingOn As Boolean = False 
    Private _pClickStart As New Point 
    Private _pClickStop As New Point 
    Private _pNow As New Point 

    Private Sub Form3_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown 
     Me._bRubberBandingOn = Not _bRubberBandingOn 

     If Me._bRubberBandingOn Then 
      If _pClickStart = Nothing Then _pClickStart = New Point 
      _pClickStart.X = e.X 
      _pClickStart.Y = e.Y 
      _pNow.X = e.X 
      _pNow.Y = e.Y 
     End If 
     Me.Invalidate() 
    End Sub 

    Private Sub Form3_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove 

     If Me._bRubberBandingOn Then 
      If _pNow = Nothing Then _pNow = New Point 
      Me._pNow.X = e.X 
      Me._pNow.Y = e.Y 
      Me.Invalidate() 
     End If 
    End Sub 

    Private Sub Form3_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp 

     Me._bRubberBandingOn = Not Me._bRubberBandingOn 
     If Not Me._bRubberBandingOn Then 
      If _pClickStop = Nothing Then _pClickStop = New Point 
      _pClickStop.X = e.X 
      _pClickStop.Y = e.Y 
      Me.Invalidate() 

     End If 
    End Sub 

    Private Sub Form3_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint 
     Dim _rRectangle As New Rectangle 
     Dim _penNew As New Pen(Color.Black, 2) 

     _rRectangle.X = _pClickStart.X 
     _rRectangle.Y = _pClickStart.Y 

     If Me._bRubberBandingOn Then 
      _rRectangle.Width = Me._pNow.X - _pClickStart.X 
      _rRectangle.Height = Me._pNow.Y - _pClickStart.Y 
     Else 
      _rRectangle.Width = Me._pClickStop.X - _pClickStart.X 
      _rRectangle.Height = Me._pClickStop.Y - _pClickStart.Y 

     End If 
     _penNew.DashStyle = Drawing2D.DashStyle.Solid 
     e.Graphics.DrawEllipse(_penNew, _rRectangle) 

    End Sub 
End Class 

이 아니면 내가 그 사용할 수있는 라이브러리를 달성 할 수있는 방법이 있습니다 :

여기에 내 현재 코드는? 그 선/도형의 핸들을 가져온 다음 스크린 샷을 만드는 데 사용할 수있는 방법이 있습니까? 나는 실제로 이것을 조사했지만 아직 의미있는 것을 찾지 못했습니다. 미리 감사드립니다.

답변

0

당신의 상단에 타원을 그리는 이미지를 가지고 다음을 수행하십시오

Dim theBitmap As Bitmap = DirectCast(Image.FromFile("PathToFileYouAreDrawingEllipseOn.bmp"), Bitmap) 
Dim theEllipseBitmap As New Bitmap(theBitmap.Width, theBitmap.Height) 
Dim theGraphics As Graphics = Graphics.FromImage(theEllipseBitmap) 
Dim theGraphicsPath As New GraphicsPath() 

' The (10,10) coordinates here are made up, you will need to take what is drawn by the user (starting x,y; ending x,y, etc.) 
theGraphicsPath.AddEllipse(10, 10, theBitmap.Width - 20, theBitmap.Height - 20) 
theGraphics.Clear(Color.Magenta) 
theGraphics.SetClip(theGraphicsPath) 
theGraphics.DrawImage(theBitmap, New Rectangle(0, 0, theBitmap.Width, theBitmap.Height), 0, 0, theBitmap.Width, theBitmap.Height, _ 
GraphicsUnit.Pixel) 
theGraphics.Dispose() 
theEllipseBitmap.MakeTransparent(Color.Magenta) 

' Save the ellipse bitmap to a PNG file format 
string fileName = "PathToYourDesiredOutput.png" 
theEllipseBitmap.Save(fileName, System.Drawing.Imaging.ImageFormat.Png) 
관련 문제