Michael Müller Anywhere Member Licensed User Longtime User Nov 23, 2021 #1 Hello, I need to transfer pictures to a VB6 Application via winsock (encrypted before). With the wllknown methods I get a byte() Array that is UTF8 encodet. How can I read the raw bytes of a file (Picture) and put it in a long string to transfer it? Thank you!
Hello, I need to transfer pictures to a VB6 Application via winsock (encrypted before). With the wllknown methods I get a byte() Array that is UTF8 encodet. How can I read the raw bytes of a file (Picture) and put it in a long string to transfer it? Thank you!
DonManfred Expert Licensed User Longtime User Nov 23, 2021 #2 Michael Müller Anywhere said: How can I read the raw bytes of a file Click to expand... B4X: Copy dim bytes() as Byte = File.ReadBytes(path, filename) If you need to have a string then you need to convert the bytes to base64 or hex. B4A - Encryption Last edited: Nov 23, 2021 Upvote 1
Michael Müller Anywhere said: How can I read the raw bytes of a file Click to expand... B4X: Copy dim bytes() as Byte = File.ReadBytes(path, filename) If you need to have a string then you need to convert the bytes to base64 or hex. B4A - Encryption
Michael Müller Anywhere Member Licensed User Longtime User Nov 23, 2021 #3 DonManfred said: B4X: Copy dim bytes() as Byte = File.ReadBytes(path, filename) If you need to have a string then you need to convert the bytes to base64 or hex. B4A - Encryption Click to expand... Thank you Don!!! This works. For all: Code: Copy Dim data() As Byte = File.ReadBytes(path, filename) Dim Bconv As ByteConverter datastring = Bconv.HexFromBytes(data) Code: Copy file_content = Hex2Ascii(input) Function Hex2Ascii(Hcs As String) As String Dim l As Long Dim a As Long l = Len(Hcs) For a = 1 To l Step 2 Hex2Ascii = Hex2Ascii & Chr$(Val("&H" & Mid(Hcs, a, 2))) Next End Function Upvote 0
DonManfred said: B4X: Copy dim bytes() as Byte = File.ReadBytes(path, filename) If you need to have a string then you need to convert the bytes to base64 or hex. B4A - Encryption Click to expand... Thank you Don!!! This works. For all: Code: Copy Dim data() As Byte = File.ReadBytes(path, filename) Dim Bconv As ByteConverter datastring = Bconv.HexFromBytes(data) Code: Copy file_content = Hex2Ascii(input) Function Hex2Ascii(Hcs As String) As String Dim l As Long Dim a As Long l = Len(Hcs) For a = 1 To l Step 2 Hex2Ascii = Hex2Ascii & Chr$(Val("&H" & Mid(Hcs, a, 2))) Next End Function
Erel B4X founder Staff member Licensed User Longtime User Nov 24, 2021 #4 Tip - assuming that the file is not small, this code is very inefficient: Code: Copy Hex2Ascii = Hex2Ascii & Chr$(Val("&H" & Mid(Hcs, a, 2))) Strings are immutable, which means that for every new character the whole string is copied. You should use StringBuilder. Upvote 0
Tip - assuming that the file is not small, this code is very inefficient: Code: Copy Hex2Ascii = Hex2Ascii & Chr$(Val("&H" & Mid(Hcs, a, 2))) Strings are immutable, which means that for every new character the whole string is copied. You should use StringBuilder.
Michael Müller Anywhere Member Licensed User Longtime User Nov 25, 2021 #5 You were right. The program froze it at more than 200,000 bytes and I had to split the string. Now it works wonderfully! Upvote 0
You were right. The program froze it at more than 200,000 bytes and I had to split the string. Now it works wonderfully!