D
Devon_Nullman
Guest
I have a screen capture program, the form is a small borderless form with a label "LblFill"
Here's the code
Public Class Form1
Private StPosX, StPosY, EnPosX, EnPosY As Integer
Private ScreenImg As Image
Private CroppedImage As Bitmap
Sub CaptureScreen()
Dim hgt As Integer = My.Computer.Screen.WorkingArea.Height
Dim wdh As Integer = My.Computer.Screen.WorkingArea.Width
Dim scrn As New Bitmap(wdh, hgt, Imaging.PixelFormat.Format64bppArgb)
Using gp As Graphics = Graphics.FromImage(scrn)
gp.CopyFromScreen(0, 0, 0, 0, New Size(wdh, hgt))
End Using
Me.BackgroundImage = scrn
ScreenImg = scrn
Me.LblFill.BackColor = Color.FromArgb(150, Color.Silver)
Me.LblFill.Visible = False
Me.Location = New Point(0, 0)
Me.Size = New Size(wdh, hgt)
End Sub
Private Sub LblFill_Click(sender As Object, e As EventArgs) Handles LblFill.Click
Call CaptureScreen()
Me.TopMost = True
End Sub
Private Sub Form1_MouseDown(sender As Object, e As MouseEventArgs) Handles Me.MouseDown
StPosX = e.X
StPosY = e.Y
End Sub
Private Sub Form1_MouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove
Dim hgt As Integer = My.Computer.Screen.WorkingArea.Width
Dim wdh As Integer = My.Computer.Screen.WorkingArea.Width
If e.Button = Windows.Forms.MouseButtons.Left Then
LblFill.Visible = True
LblFill.TextAlign = ContentAlignment.MiddleCenter
LblFill.Left = IIf(StPosX > e.X, e.X, StPosX)
LblFill.Top = IIf(StPosY > e.Y, e.Y, StPosY)
LblFill.Width = Math.Abs(StPosX - e.X)
LblFill.Height = Math.Abs(StPosY - e.Y)
LblFill.Text = "Capturing" & vbNewLine & LblFill.Width.ToString & " x " & LblFill.Height.ToString
Using G As Graphics = Me.CreateGraphics
Using P As Pen = New Pen(Brushes.Red, 3)
G.DrawRectangle(P, LblFill.Left, LblFill.Top, LblFill.Width, LblFill.Height)
End Using
End Using
End If
End Sub
Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
If StPosX <> e.X And StPosY <> e.Y Then
EnPosX = e.X
EnPosY = e.Y
CroppedImage = New Bitmap(Math.Abs(StPosX - EnPosX), Math.Abs(StPosY - EnPosY))
Using gp As Graphics = Graphics.FromImage(CroppedImage)
gp.DrawImage(ScreenImg, -IIf(StPosX > EnPosX, EnPosX, StPosX), -IIf(StPosY > EnPosY, EnPosY, StPosY))
End Using
CroppedImage.Save("D:\TEST_TEMP_TEST.jpg", Imaging.ImageFormat.Jpeg)
ScreenImg.Dispose()
CroppedImage.Dispose()
End
End If
End
End Sub
End Class
It works, image is ok - the red border is what has me stumped, as long as the mouse is dragged to capture more, its fine, but if you go back, it leaved the border behind like this:
Help please
Continue reading...
Here's the code
Public Class Form1
Private StPosX, StPosY, EnPosX, EnPosY As Integer
Private ScreenImg As Image
Private CroppedImage As Bitmap
Sub CaptureScreen()
Dim hgt As Integer = My.Computer.Screen.WorkingArea.Height
Dim wdh As Integer = My.Computer.Screen.WorkingArea.Width
Dim scrn As New Bitmap(wdh, hgt, Imaging.PixelFormat.Format64bppArgb)
Using gp As Graphics = Graphics.FromImage(scrn)
gp.CopyFromScreen(0, 0, 0, 0, New Size(wdh, hgt))
End Using
Me.BackgroundImage = scrn
ScreenImg = scrn
Me.LblFill.BackColor = Color.FromArgb(150, Color.Silver)
Me.LblFill.Visible = False
Me.Location = New Point(0, 0)
Me.Size = New Size(wdh, hgt)
End Sub
Private Sub LblFill_Click(sender As Object, e As EventArgs) Handles LblFill.Click
Call CaptureScreen()
Me.TopMost = True
End Sub
Private Sub Form1_MouseDown(sender As Object, e As MouseEventArgs) Handles Me.MouseDown
StPosX = e.X
StPosY = e.Y
End Sub
Private Sub Form1_MouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove
Dim hgt As Integer = My.Computer.Screen.WorkingArea.Width
Dim wdh As Integer = My.Computer.Screen.WorkingArea.Width
If e.Button = Windows.Forms.MouseButtons.Left Then
LblFill.Visible = True
LblFill.TextAlign = ContentAlignment.MiddleCenter
LblFill.Left = IIf(StPosX > e.X, e.X, StPosX)
LblFill.Top = IIf(StPosY > e.Y, e.Y, StPosY)
LblFill.Width = Math.Abs(StPosX - e.X)
LblFill.Height = Math.Abs(StPosY - e.Y)
LblFill.Text = "Capturing" & vbNewLine & LblFill.Width.ToString & " x " & LblFill.Height.ToString
Using G As Graphics = Me.CreateGraphics
Using P As Pen = New Pen(Brushes.Red, 3)
G.DrawRectangle(P, LblFill.Left, LblFill.Top, LblFill.Width, LblFill.Height)
End Using
End Using
End If
End Sub
Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
If StPosX <> e.X And StPosY <> e.Y Then
EnPosX = e.X
EnPosY = e.Y
CroppedImage = New Bitmap(Math.Abs(StPosX - EnPosX), Math.Abs(StPosY - EnPosY))
Using gp As Graphics = Graphics.FromImage(CroppedImage)
gp.DrawImage(ScreenImg, -IIf(StPosX > EnPosX, EnPosX, StPosX), -IIf(StPosY > EnPosY, EnPosY, StPosY))
End Using
CroppedImage.Save("D:\TEST_TEMP_TEST.jpg", Imaging.ImageFormat.Jpeg)
ScreenImg.Dispose()
CroppedImage.Dispose()
End
End If
End
End Sub
End Class
It works, image is ok - the red border is what has me stumped, as long as the mouse is dragged to capture more, its fine, but if you go back, it leaved the border behind like this:
Help please
Continue reading...