Convert base 64

Gawron

New member
Joined
Feb 2, 2006
Messages
2
Programming Experience
Beginner
I have an application that goes out to a shipping company and gets the shipping label for the box being shipped. I am able to generate the XML and get the label from the company. I can display the label in a text box as a string. I need to be able to convert this label to a GIF file so I can redirect the user to this file. Below is the code I tried to use. It creates a file, but not one that can be displayed. Thanks for the help.

Public Sub ConvertFiletoBinary()
Dim inFile As System.IO.StreamReader
Dim base64String As String
Dim inputFilename As String = "c:\j.txt"
Dim outputfilename As String = "C:\nike.gif"
Try
Dim base64CharArray() As Char
inFile = New System.IO.StreamReader(inputFileName, _
System.Text.Encoding.ASCII)
base64CharArray =
New Char(inFile.BaseStream.Length) {}
inFile.Read(base64CharArray, 0, inFile.BaseStream.Length)
base64String =
New String(base64CharArray, _
0, _
base64CharArray.Length - 1)
Catch exp As System.Exception
' Error creating stream or reading from it.
System.Console.WriteLine("{0}", exp.Message)
Return
End Try
' Convert the Base64 UUEncoded input into binary output.
Dim binaryData() As Byte
Try
binaryData = System.Convert.FromBase64String(base64String)
Catch exp As System.ArgumentNullException
System.Console.WriteLine("Base 64 string is null.")
Return
Catch exp As System.FormatException
System.Console.WriteLine("Base 64 length is not 4 or is " + _
"not an even multiple of 4.")
Return
End Try
'Write out the decoded data.
Dim outFile As System.IO.FileStream
Try
outFile = New System.IO.FileStream(outputFileName, _
System.IO.FileMode.Create, _
System.IO.FileAccess.Write)
outFile.Write(binaryData, 0, binaryData.Length - 1)
outFile.Close()
Catch exp As System.Exception
' Error creating stream or writing to it.
System.Console.WriteLine("{0}", exp.Message)
End Try
End Sub
 
is this what you mean?

So you basically, you have some text like this:

341D87A6N2L

Any you need it to be converted to an image and saved like this:
label.PNG


If that's what you need, then why not do this:
  1. Make a new bitmap object with the correct dimiensions
  2. Print the string onto the image
  3. Save the bitmap file
 
Kinda different

What I have is a string of encoded data. Its basically a string representation of a graphic image. If I print it to the text box, then I will just have the string. It basically a encrypted file. That way I can retrieve it via an XML request.


Thanks for the reply.
 
Back
Top