Hello, so I am trying to make a program that will convert an image from a screenshot of the users desktop to base64 string so that I can send it to my websites php API.
Here is what i have so far... also know. This is my very first program with VB so it's probably completely wrong but I would greatly appreciate it if you could help me out! Thanks!
The problem is right now that it's not displaying the String in the message box... if this code is completely wrong or not possible I'll get it lol. Like I said, first program. Just trying to piece together stuff I've found and see if it works.
Best Regards, Aurora
Here is what i have so far... also know. This is my very first program with VB so it's probably completely wrong but I would greatly appreciate it if you could help me out! Thanks!
Code:
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim sd As Bitmap
'Taking the screenshot of desktop here
sd = New Bitmap(My.Computer.Screen.WorkingArea.Width, _
My.Computer.Screen.WorkingArea.Height, _
Imaging.PixelFormat.Format32bppArgb)
Dim g As Graphics = Graphics.FromImage(sd)
g.CopyFromScreen(New Point(0, 0), New Point(0, 0), _
New Size(My.Computer.Screen.WorkingArea.Width, _
My.Computer.Screen.WorkingArea.Height))
'Converting the image to a byte[] to later be converted to base64 string
Dim imgStream As MemoryStream = New MemoryStream()
sd.Save(imgStream, System.Drawing.Imaging.ImageFormat.Png)
imgStream.Close()
Dim byteArray As Byte() = imgStream.ToArray()
imgStream.Dispose()
'Convert the byte[] to base64 string for use with WebRequest to upload.
Dim final As String
final = Convert.ToBase64String(byteArray)
'Display the string to know that it's working.
MsgBox(final)
End Sub
Best Regards, Aurora