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.
Thanks for sharing excellent post mate!
(Nov 14, 2014 04:08 PM)AEDEAD Wrote:  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.

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... >.>
I post my opinions, please try not to be offended... I am not saying I am superior, but my interpretation of what you are saying may be befuddling.
(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:33 PM)AEDEAD Wrote:  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.

You do not understand memory usage or any form of optimizing a program. Please l3rn to write your own code if you want any sort of credit for the stuff you post. This looks like random junk from google just copy and pasted together to eventually make it work in the 80 lines of code (I didn't take the time to do a line count).

If you do not understand what I am saying please learn English before coming back. Either that or brush up on the literally basic programming terms...

https://hackforums.net/showthread.php?ti...id43316439 - Much more efficient... Posted it last night, in a thread you posted in. I corrected your code, and your all upset about it, trying to get skid pointz (for copy and pasting code)...

This is why I hate how people un-intelligently dim variables all over the place, they don't understand memory efficiency in the slightest... xD

The thing is is you cannot really "screw up" with GDI. It has many many "safeguards" in attempt to stop you from screwing up... I assume thats why your asking "Is it my GDI?"... No it is general lack of optimizing... You dont understand variables which is a key part of programming... Something that you will probably never do, atleast not beyond posting random snippets which are so inefficient it begs the question "why use them"...

I see no substance worthy of creating this thread in the slightest... Anyone should be able to google and find this information for themselves... It is a heavily used thing... Most people will end up finding much more efficient code from googling is the sad thing...

Also I am assuming this is the source for this information? https://hackforums.net/showthread.php?tid=3163503
Again. At a minimum, Give credit to the person you are leeching from... >.>
I post my opinions, please try not to be offended... I am not saying I am superior, but my interpretation of what you are saying may be befuddling.
(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.
(Nov 14, 2014 06:15 PM)AEDEAD Wrote:  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....

So this is your third plus account on these forums, where you know that creating alternate accounts and closing the old one is against the TOS? (Aside from a couple extraneous situations where you deal with staff ahead of time). Something you should be permabanned for?

A) I do not believe that that poster is "you", just because you claim it is...
B) Just because the cruddy code is posted before you does not make it less cruddy...

At least your able to admit that all of this is leeched... That's a "first"...

(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.

So you shouldn't mind being called out or corrected when your code is un-optimized, inefficient, etc. You should not assume that you will get any credit whatsoever for anything you may write with this crazy philosophy... "I don't care about citing my sources, I just want to make everyone believe I'm special for trying to steal credit from another's work"...

(Nov 14, 2014 06:15 PM)AEDEAD Wrote:  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.

Yep I have a decent knowledge of C++. Technically my signature is not updated, and technically I have "yet to" "eventually learn" C++ and such... I don't know why you are referring to Assembly (without writing it out), as that is in no way shape or form a part of my signature...

Me posting in the .Net Forums does not mean I do not know the language... I rarely post in the C# forum, and I am pretty proficient in C#. I never have posted in PHP, Java, C++, Html/CSS/Javascript forums either... Does not mean that I do not know the language... Maybe I just like VB.Net, maybe I have a clear understanding of VB.Net, and would like to teach others that it is not a "dumb language" like some may assume... Its not perfect, but it is "more fun" to work with in my opinion. If I am going to be fixing peoples code, I want to have fun with it. For some that may be in C++. So I generally leave the C++ forum to said people. Honestly though, I don't really care if people believe me when I state those things... It is not for the e-points... I just always see fellow programmers doing it, and thought well if some random skid needs help with an upload function or whatever, he might PM me if he sees I can code in PHP/whatever. I certainly don't go around claiming I am the best coder because of that...

What I do not understand is you are always on your High Horse... "I've been working with C before you even knew what VB was"... So if I am at fault, for not posting in the C++ forums, why you not at fault? I did not even claim to be "good at it"... Sounds like someone is trying to use some random source of C++ code they found to try to "prove something" to me... Please seek psychological help... Go talk to someone... You have some sort of a superiority problem... It will cause you problems all through-out your life from here on out if you don't learn to deal with it now...

(Nov 14, 2014 06:15 PM)AEDEAD Wrote:  You constantly take shots at me for no dried raisin, i'm tired of it.

First off its reason, not raisin... >.> I can ignore most misspellings but that is a strange one...
Says the person taking shots at me "for no reason"... Again, just don't consider you have a stance in the problem, classic narcissism... >.>
I "take shots" at people who claim to know something when literally all they do is copy and paste. Then when people note it they get angry and flame other users... It is no benefit to the forums to have scum around here like you. So if you feel hurt. Please leave. If not you are continuing to sign yourself up for whatever a user might say about the random and cruddy code you copy and paste...
Take a look at your rep. I am not alone in these beliefs...

I get it your goal is to be the idiot, who gets appreciated for not knowing a thing, and getting rep for copy and pasting random bits of code... All I am saying is that is not going to happen... And even if it did hypothetically happen, what would you gain from it in comparison to actually learning how to program these sorts of things on your own... I am saying there is simply a logic error in your brain somewhere... Stop trying to be the idiot I was describing... Better yourself, in order to better the community... Posting these random codes is not bettering the community... >.>
I post my opinions, please try not to be offended... I am not saying I am superior, but my interpretation of what you are saying may be befuddling.
when and where do i get my dried raisins?


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 325 Apr 22, 2021 08:27 AM
Last Post: Scapula™
[.NET] by ryanrlMar 16, 2017 10:47 PM 8 585 Mar 16, 2017 10:47 PM
Last Post: Ninja