Image from client as strings [Resolved] - Dark N3BULA - Jan 13, 2015
So the solution is as follows.
Code Imports System.IO
Imports System.Drawing.Imaging
Public Class MainForm
Dim encodeType As ImageFormat = ImageFormat.Jpeg
Dim decodingString As String = String.Empty
Private Sub MainForm_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub btnOpen_Click(sender As System.Object, e As System.EventArgs) Handles btnOpen.Click
Dim newOpenFileDial As New OpenFileDialog()
newOpenFileDial.Filter = "Images(*.jpg;.*png;*.gif;*.bmp)|*.jpg;.*png;*.gif;*.bmp"
If newOpenFileDial.ShowDialog() = Windows.Forms.DialogResult.OK Then
txtPath.Text = newOpenFileDial.FileName
pbPreview.ImageLocation = txtPath.Text
End If
End Sub
Private Sub btnImagetoBase64_Click(sender As System.Object, e As System.EventArgs) Handles btnImagetoBase64.Click
txtSourceCode.Clear()
Dim encodingTypeString As String = String.Empty
If pbPreview.ImageLocation.ToLower.EndsWith(".jpg") Then
encodeType = ImageFormat.Jpeg
encodingTypeString = "data:image/jpeg;base64,"
ElseIf pbPreview.ImageLocation.ToLower.EndsWith(".png") Then
encodeType = ImageFormat.Png
encodingTypeString = "data:image/png;base64,"
ElseIf pbPreview.ImageLocation.ToLower.EndsWith(".gif") Then
encodeType = ImageFormat.Gif
encodingTypeString = "data:image/gif;base64,"
ElseIf pbPreview.ImageLocation.ToLower.EndsWith(".bmp") Then
encodeType = ImageFormat.Bmp
encodingTypeString = "data:image/bmp;base64,"
End If
decodingString = encodingTypeString
txtSourceCode.Text = encodingTypeString & ImageToBase64(pbPreview.Image, encodeType)
pbPreview.Image = Nothing
End Sub
Public Function ImageToBase64(ByVal image As Image, ByVal format As ImageFormat) As String
Using ms As New MemoryStream()
image.Save(ms, format)
Dim imageBytes As Byte() = ms.ToArray()
Dim base64String As String = Convert.ToBase64String(imageBytes)
Return base64String
End Using
End Function
Private Sub btnBase64ToImage_Click(sender As System.Object, e As System.EventArgs) Handles btnBase64ToImage.Click
txtSourceCode.Text = txtSourceCode.Text.Replace(decodingString, "")
pbPreview.Image = Base64ToImage(txtSourceCode.Text)
End Sub
Public Function Base64ToImage(ByVal base64Code As String) As Image
Dim imageBytes As Byte() = Convert.FromBase64String(base64Code)
Dim ms As New MemoryStream(imageBytes, 0, imageBytes.Length)
Dim tmpImage As Image = Image.FromStream(ms, True)
Return tmpImage
End Function
End Class
thanks to everyone who replied!🤝
* - Only3 - Jan 13, 2015
no it doesnt https://hackforums.net/showthread.php?tid=4576866t
* - Dark N3BULA - Jan 13, 2015
(Jan 13, 2015 12:07 PM)Only3 Wrote: no it doesnt https://hackforums.net/showthread.php?tid=4576866t
Im not actually trying to make a RDV mate, im sure theres an simplier way. Im using async read the incoming stream which makes it slightly tricky other.
* - Only3 - Jan 13, 2015
image bytes > base 64 > send > image bytes
* - Hawk HF - Jan 13, 2015
(Jan 13, 2015 12:18 PM)Only3 Wrote: image bytes > base 64 > send > image bytes
This.
Take a look at this thread.
It should be exactly what you're looking for.
* - Dark N3BULA - Jan 13, 2015
(Jan 13, 2015 12:33 PM)Hawk HF Wrote: This.
Take a look at this thread.
It should be exactly what you're looking for.
Bang🎉 Bang🎉
Spot on bro. Can finally get some sleep. Much appreciated
* - Ninja - Jan 13, 2015
Convert to base64 then send then convert to image again.
|