Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

Screen Capture from custom region with Upload

Region Selection + Functionality
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 Sub

IMGur 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 Sub

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.
(Nov 14, 2014 04:23 PM)Eternal Darkness Wrote:  If I need a inefficient way to do a simple task I still wouldn't use this. You can stop spamming random snippets of code you find with google now... >.>

What is inefficient and what is simple? My API? My GDI? My functionality? I stated there were a lot of ways to use this. Programs like the snippet thing for Windows have a low opacity white background which you make transparent as you select your region, the way I did it I made it go completely transparent but the Region border, because I like it like that.

I see no substance in your post, try again.
(Nov 14, 2014 04:52 PM)Eternal Darkness Wrote:  At a minimum, Give credit to the person you are leeching from... >.>

You have so many things wrong here.

First of all, I did leech my IMGURAPI but it wasn't from here let alone written down from a fucking picture, it was copy and paste from a person on a different forums and that same person also fixed the code for me when I PM'd him about it, and this was 2 or 3 years ago. That code in that picture IS the one I POSTED, MY CODE, released BY ME on a different forums....

Either way, I don't believe in giving credit or copyright. I don't live by your fictional boundaries, I don't care if someone knows all the tedious work I've done all the research I've done. As long as whatever it is, and it works that's all that matters. Since you continue to take shots at me, well how about your silly sig? It says you wanna mess with C and ASM yet all you do is program in VB. I bet you haven't ever ran an ASM code in your life. Bro how about I show you my documents and tutorials/guides on the infamous MIPS which I bet you've never even heard of you newage kiddy. I've been working with C before you even knew what VB was. You constantly take shots at me for no dried raisin, i'm tired of it.
(Nov 14, 2014 06:15 PM)AEDEAD Wrote:  Either way, I don't believe in giving credit or copyright. I don't live by your fictional boundaries, I don't care if someone knows all the tedious work I've done all the research I've done. As long as whatever it is, and it works that's all that matters. Since you continue to take shots at me, well how about your silly sig? It says you wanna mess with C and ASM yet all you do is program in VB. I bet you haven't ever ran an ASM code in your life. Bro how about I show you my documents and tutorials/guides on the infamous MIPS which I bet you've never even heard of you newage kiddy. I've been working with C before you even knew what VB was. You constantly take shots at me for no dried raisin, i'm tired of it.

That's not a belief, that's not being an asshole.
You're saying you can code in assembly? Good for you, can you stop posting crap in .net section?

btw, everyone can search.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by salemxx66Sep 30, 2021 08:39 PM 0 130 Sep 30, 2021 08:39 PM
Last Post: salemxx66
[C#] by hacker dzApr 22, 2021 08:27 AM 3 326 Apr 22, 2021 08:27 AM
Last Post: Scapula™
[.NET] by ryanrlMar 16, 2017 10:47 PM 8 589 Mar 16, 2017 10:47 PM
Last Post: Ninja