Region Selection + Functionality
IMGur API
Probably useful for somebody, there is tons of ways you can use this personally I think it looks best this way.
I'll upload a full source if anybody wants me to.
Code
Private MyRectangle As Rectangle
Private Drawing As Boolean = False
Private StartX, StartY, CursorX, CursorY As Single
Private Sub Region_Drag_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
If Drawing = True Then
Dim Oral_Pen As New Pen(Brushes.Red, 2)
Oral_Pen.DashStyle = Drawing2D.DashStyle.Solid
MyRectangle = New Rectangle(Min(StartX, CursorX), _
Min(StartY, CursorY), _
Abs(StartX - CursorX), _
Abs(StartY - CursorY))
e.Graphics.FillRectangle(New SolidBrush(Color.Transparent), MyRectangle)
e.Graphics.DrawRectangle(Oral_Pen, MyRectangle)
End If
End Sub
Private Sub Region_Drag_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Escape Then
Me.Close()
End If
End Sub
Private Sub Region_Drag_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
Me.BackColor = Color.Fuchsia
Me.Opacity = 100%
Drawing = True
StartX = e.X
StartY = e.Y
CursorX = e.X
CursorY = e.Y
End Sub
Private Sub Region_Drag_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
If Not Drawing Then Exit Sub
Dim G As Graphics = Me.CreateGraphics
CursorX = e.X
CursorY = e.Y
Me.Invalidate()
End Sub
Private Sub Region_Drag_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
Drawing = False
Dim G As Graphics = Me.CreateGraphics
G.DrawRectangle(Pens.Black, MyRectangle.X, MyRectangle.Y, MyRectangle.Width, MyRectangle.Height)
Me.Visible = False
Try
bmp = New Bitmap(MyRectangle.Width, MyRectangle.Height, PixelFormat.Format32bppArgb)
graphics = graphics.FromImage(bmp)
graphics.CopyFromScreen(MyRectangle.X, MyRectangle.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy)
saveDialog.Filter = "png image|*.png"
saveDialog.Title = "Save image as"
saveDialog.ShowDialog()
If saveDialog.FileName <> "" Then
bmp.Save(saveDialog.FileName, ImageFormat.Png)
upload()
End If
Catch ex As Exception : Finally
bmp = Nothing
graphics = Nothing
Me.WindowState = FormWindowState.Minimized
Me.Hide()
End Try
Me.Visible = True
Me.Invalidate()
Me.Dispose()
Application.Exit()
End Sub
Private Sub Region_Drag_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Focus()
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
Me.TopMost = True
Me.Location = New Point(0, 0)
Me.Size = Screen.PrimaryScreen.Bounds.Size
Me.DoubleBuffered = True
End SubIMGur API
Code
Dim saveDialog As New SaveFileDialog
Dim bmp As Bitmap
Dim graphics As Graphics
Dim KeyCode As String = File.ReadAllText(Application.StartupPath & "\APIKey.txt") 'To publish
Sub upload()
Dim apiKey As String = KeyCode 'To Publish
Dim imageData() As Byte
Dim fileStream As FileStream = File.OpenRead(saveDialog.FileName)
imageData = New Byte((fileStream.Length) - 1) {}
fileStream.Read(imageData, 0, imageData.Length)
fileStream.Close()
Dim uploadRequestString As String = HttpUtility.UrlEncode("image", Encoding.UTF8) + "=" + HttpUtility.UrlEncode(System.Convert.ToBase64String(imageData)) + "&" + HttpUtility.UrlEncode("key", Encoding.UTF8) + "=" + HttpUtility.UrlEncode(apiKey, Encoding.UTF8)
Dim webRequest As HttpWebRequest = CType(Net.WebRequest.Create("http://api.imgur.com/2/upload"), HttpWebRequest)
webRequest.Method = "POST"
webRequest.ContentType = "application/x-www-form-urlencoded"
webRequest.ServicePoint.Expect100Continue = False
Dim streamWriter As IO.StreamWriter = New IO.StreamWriter(webRequest.GetRequestStream)
streamWriter.Write(uploadRequestString)
streamWriter.Close()
Dim response As WebResponse = webRequest.GetResponse
Dim responseStream As Stream = response.GetResponseStream
Dim responseReader As StreamReader = New StreamReader(responseStream)
Dim responseString As String = responseReader.ReadToEnd
Dim ImageURL As String = Split(responseString, "<original>")(1).Split("<")(0)
Dim X As String
X = ImageURL
System.Diagnostics.Process.Start(X)
End SubProbably useful for somebody, there is tons of ways you can use this personally I think it looks best this way.
I'll upload a full source if anybody wants me to.
