Results 1 to 31 of 31

Thread: JPEG, Base 64

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2007
    Posts
    17

    JPEG, Base 64

    Does any one knows how to use VB to convert jpeg file format into base64. I'm still new in VB. What I've got only class module file (.cls) and I have no idea on how to use it. Thanks in advance..

    Also found online conversion here :
    http://www.motobit.com/util/base64-decoder-encoder.asp

  2. #2
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Re: JPEG, Base 64

    Have you considered asking for help from the teacher who gave you the task?
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2007
    Posts
    17

    Re: JPEG, Base 64

    I don't think she knows very well about that. That's why I'm asking here. I'm an electrical student. I'm supposed to make the picture that is converted(base 64) can be transfered through serial communication. Both part about serial communication and hardware were already done. Now, it's the last part which I supposed to convert the image file....

    Isk.....

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: JPEG, Base 64

    What is the purpose of the cls file? My guess is it is a byte to Base64 converter. Maybe post a couple of the public function names so we can see.
    If it is a byte to base64 converter, open the JPG file in binary, using VB. Then read the file into a byte array, send the array to the class function which should return another array or string. Send that array/string across the net.

    To use the cls file. Declare it in your routines, something like the following.
    Have no idea what your class filename is, let's just assume it is default Class1.
    Dim myClass As Class1
    Set myClass = New Class1
    -- now you can call its functions, i.e., myClass.FunctionName
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Sep 2007
    Posts
    17

    Re: JPEG, Base 64

    Quote Originally Posted by LaVolpe
    What is the purpose of the cls file? My guess is it is a byte to Base64 converter. Maybe post a couple of the public function names so we can see.
    If it is a byte to base64 converter, open the JPG file in binary, using VB. Then read the file into a byte array, send the array to the class function which should return another array or string. Send that array/string across the net.

    To use the cls file. Declare it in your routines, something like the following.
    Have no idea what your class filename is, let's just assume it is default Class1.
    Dim myClass As Class1
    Set myClass = New Class1
    -- now you can call its functions, i.e., myClass.FunctionName

    Actually I found two example.. So I guess I'll show both of them to you to see... Both of them were really different from each other. Maybe the way of the software design is different.. I don't know.. Thanks..
    Attached Files Attached Files

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: JPEG, Base 64

    Not to sure about the 1st class you posted; I discovered errors in there and wouldn't trust it. Not even worth the time to fix it because there are so many Base64 encode/decoders about.

    The 2nd one appears correct and is the same one found on this site. Look at where it came from and read the postings; you should see what you are looking for.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Sep 2007
    Posts
    17

    Re: JPEG, Base 64

    That page talks more on how to do the testing..
    Here's some of my code :

    Code:
    Private Sub cmdOpen_Click()
        cdOpen.Filter = "Joint Photo Group (*.jpg)|*.jpg|Joint Photo Expert Group (*.jpeg)|*.jpeg"
        cdOpen.ShowOpen
        If Not vbCancel Then
           txtFileName = cdOpen.FileName
        End If
    End Sub
    
    Private Sub cmdEncode_Click() 'the problems is here.
    Dim myClass As Class1 
    Set myClass = New Class1
    myClass.Encode
    End Sub
    How am I suppose to convert the file ? The encoded file will then display on a text field as shown as below :


  8. #8
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: JPEG, Base 64

    Quote Originally Posted by bearboss_85
    That page talks more on how to do the testing..
    Here's some of my code
    Yes, but it also showed you how to get the byte data into a string so you can use it with that class. It is Post #8 on that link. I've tweaked your code a bit to include what I was trying to get you to see.

    Code:
    Private Sub cmdOpen_Click()
        cdOpen.Filter = "Joint Photo Group (*.jpg)|*.jpg|Joint Photo Expert Group (*.jpeg)|*.jpeg"
        cdOpen.ShowOpen
        If Not vbCancel Then
           txtFileName = cdOpen.FileName
        End If
    End Sub
    
    Private Sub cmdEncode_Click() 'the problems is here.
    Dim sBase64 As String
    Dim sJPG as String
    Dim iFile As Integer
    Dim myClass As Class1 
    Set myClass = New Class1
    
        iFile = FreeFile()
        Open txtFileName.Text For Binary Access Read Lock Write As #iFile
        sJPG = String$(LOF(iFile), Chr$(0))
        Get #iFile, , sJPG
        Close #iFile
    sBase64 = myClass.Encode(sJPG) ' the result from the function is what you want
    End Sub
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Sep 2007
    Posts
    17

    Re: JPEG, Base 64

    So, I guess after this :
    sBase64 = myClass.Encode(sJPG)

    I should put this :
    Text1.Text = myClass.Encode(sJPG)
    to be able to see the real code.....

    And the decoding code will be the same applied to the encoding one. But how I want to save the decoding file into one single file?
    Last edited by bearboss_85; Mar 26th, 2008 at 09:45 AM.

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Sep 2007
    Posts
    17

    Re: JPEG, Base 64

    I still don't have solution for the decoding function...

    Here's my code :

    Code:
    Private Sub cmdDecode_Click()
     
    On Error Resume Next
    
    Dim sBase64 As String
    Dim sJPG As Integer
    Dim iFile As Integer 'maybe the problems is here
    Dim myClass As Class1
    Set myClass = New Class1
    
        iFile = FreeFile()
        Save Text2.Text 'don't know how to call the encoded code on the receiver text display
        sJPG = String$(LOF(iFile), Chr$(0))
        Get #iFile, , sJPG
        Close #iFile
    sBase64 = myClass.Decode(sJPG) 'is this how to save the file?
    cdSave.Filter = "Joint Photo Group (*.jpg)|*.jpg|Joint Photo Expert Group (*.jpeg)|*.jpeg"
    cdSave.ShowSave
    If Err Then
        
        MsgBox "Dialog Cancelled"
        Exit Sub
    End If
    
    End Sub

  11. #11
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: JPEG, Base 64

    Quote Originally Posted by bearboss_85
    is this how to save the file?
    not quite. Simply calling cdSave.ShowSave saves nothing, it does return the path & file name, in the .FileName property, of where the user wants the data saved; it is up to you to create a file and write the data.

    Edited: Oh, your save filter is for JPG type extensions; saving a Base64 converted JPG image with a JPG extension does not make it a JPG. It will no longer display an image. To get it to JPG format again, you must decode the Base64 to binary data & then write the binary data to a file with a JPG extension. Understand?
    Last edited by LaVolpe; Mar 27th, 2008 at 03:15 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Sep 2007
    Posts
    17

    Re: JPEG, Base 64

    I'm sorry.. So I need to convert it to binary first and then I can convert the binary data into JPG file back which means I need to convert the transmitted data once again into binaries to get the exact JPG files. LOL.. You get me a little confused..

    Do you have any example that I can see or follow?

  13. #13
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: JPEG, Base 64

    I can write an example, but you should do that instead. Here is what is happening. It isn't confusing if you think about it.

    1. You have a JPG file, ok?
    2. You convert its bytes to a Base64 string for whatever purposes. Now it is no longer a JPG file, it is encoded text, encrypted. It is no longer what it was.
    3. To get it back, you have to decode the Base64 string back to its original format.

    The above is also the basics of encryption and compression routines. This is what happens alot on networks: get binary data, convert to Base64, send across network, receive on other end, convert from Base64, save binary data.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  14. #14

    Thread Starter
    Junior Member
    Join Date
    Sep 2007
    Posts
    17

    Re: JPEG, Base 64

    1. You have a JPG file, ok? (OK)
    2. You convert its bytes to a Base64 string for whatever purposes. Now it is no longer a JPG file, it is encoded text, encrypted. It is no longer what it was. (Yes.. It is no longer what it was)
    3. To get it back, you have to decode the Base64 string back to its original format. (By this, you means that to decode the Base64 string back to its original format, I need to convert it FIRST to binary data & then write the binary data to a file with a JPG extension?)

  15. #15
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: JPEG, Base 64

    Yepper. Just saving Base64 encrypted data to a file with a .jpg extension is useless -- it isn't a JPG while it is encrypted.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  16. #16

    Thread Starter
    Junior Member
    Join Date
    Sep 2007
    Posts
    17

    Re: JPEG, Base 64

    I just think of this... What are decoding function in the class module for as if I need to convert it to binary first? Do I still need to decode it first and then turn it to binary? Or I just make the encoded data into binary and save it to JPG file? I think this is why I've got confused in the first place.

  17. #17
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: JPEG, Base 64

    Base64 uses only characters in a small range of the possible 255 ascii characters and prevents potential of transmission protocols interpreting some bytes incorrectly or as some special commands. I think this link explains it pretty well.

    Your original question was how to convert jpg to Base64. I think that question was answered and you can do that now. The entire process is pretty straightforward:
    1. Convert binary (jpg image file) to Base64 (encoded)
    2. Transmit/Send to wherever
    3. It is received from transmission
    4. Decode Base64 to binary & save data. Decoded data is now a JPG again.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  18. #18

    Thread Starter
    Junior Member
    Join Date
    Sep 2007
    Posts
    17

    Re: JPEG, Base 64

    Is this helping?
    http://www.motobit.com/tips/detpg_Base64/

    I still work on the decoding but still don't have the result.....

  19. #19

    Thread Starter
    Junior Member
    Join Date
    Sep 2007
    Posts
    17

    Re: JPEG, Base 64

    I've got this:

    Code:
    Private Function ConverttoBinary(char As Byte) As String
    Dim i As Integer
    Dim x As Integer
    Dim strBinByte As String
    
        For i = 7 To 0 Step -1
            x = char And (2 ^ i)
            
            Select Case x
            
                Case Is > 0
                   strBinByte = strBinByte & "1"
                   
                Case Else
                    strBinByte = strBinByte & "0"
               
            End Select
            
        Next i
        
        ConverttoBinary = strBinByte
        
    End Function
    I've tried this :

    Code:
    Dim sBase64 As String
    Dim sJPG As String
    Dim iFile As Integer
    Dim myClass As Class1
    Dim i As Integer
    Dim strByte As String
    Dim B() As Byte
    Dim intLen As Integer
    Set myClass = New Class1
    
        iFile = FreeFile()
        Open Text2.Text For Binary Access Read Lock Write As #iFile
        sJPG = String$(LOF(iFile), Chr$(0))
        Get #iFile, , sJPG
        Close #iFile
    sBase64 = myClass.Decode(sJPG)
    
    B = myClass.Decode(sJPG)
    intLen = UBound(B)
    
    For i = 0 To intLen Step 2
            strByte = ConverttoBinary(B(i))
    
    Next i
    
    cdSave.Filter = "Joint Photo Group (*.jpg)|*.jpg|Joint Photo Expert Group (*.jpeg)|*.jpeg"
    cdSave.ShowSave
    If Err Then
        ' This code runs if the dialog was cancelled
        MsgBox "Dialog Cancelled"
        Exit Sub
    End If
    
    End Sub
    But still can't make it into one file.... Any suggestion?

  20. #20
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: JPEG, Base 64

    See if this works for you. Assumption is that file in Text2 is original JPG encoded as Base64
    Code:
    Dim sBase64 As String
    Dim sJPG As String
    Dim iFile As Integer
    Dim myClass As Class1
    
        cdSave.Filter = "Joint Photo Group (*.jpg)|*.jpg|Joint Photo Expert Group (*.jpeg)|*.jpeg"
        cdSave.ShowSave
        If Err Then
            ' This code runs if the dialog was cancelled
            MsgBox "Dialog Cancelled"
        Else
            Set myClass = New Class1
            iFile = FreeFile()
            Open Text2.Text For Binary Access Read Lock Write As #iFile
            sJPG = String$(LOF(iFile), 0)
            Get #iFile, , sJPG
            Close #iFile
        
            sBase64 = myClass.Decode(sJPG)
            iFile = FreeFile()
            Open cdSave.FileName For Binary As #iFile
            Put #iFile, , sBase64
            Close #iFile
        End If
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  21. #21

    Thread Starter
    Junior Member
    Join Date
    Sep 2007
    Posts
    17

    Re: JPEG, Base 64

    Quote Originally Posted by LaVolpe
    See if this works for you. Assumption is that file in Text2 is original JPG encoded as Base64
    Code:
    Dim sBase64 As String
    Dim sJPG As String
    Dim iFile As Integer
    Dim myClass As Class1
    
        cdSave.Filter = "Joint Photo Group (*.jpg)|*.jpg|Joint Photo Expert Group (*.jpeg)|*.jpeg"
        cdSave.ShowSave
        If Err Then
            ' This code runs if the dialog was cancelled
            MsgBox "Dialog Cancelled"
        Else
            Set myClass = New Class1
            iFile = FreeFile()
            Open Text2.Text For Binary Access Read Lock Write As #iFile
            sJPG = String$(LOF(iFile), 0)
            Get #iFile, , sJPG
            Close #iFile
        
            sBase64 = myClass.Decode(sJPG)
            iFile = FreeFile()
            Open cdSave.FileName For Binary As #iFile
            Put #iFile, , sBase64
            Close #iFile
        End If
    I've had this :

    Runtime error '53'

    File not found.


  22. #22
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: JPEG, Base 64

    In what line? that would be helpful.
    What do you have in Text2? What does cdSave.FileName contain?
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  23. #23
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: JPEG, Base 64

    When I was creating my email application I needed a way to send images and other binary files as attachments so I went looking for some base64 encoders. Well, I found a few and tried them in my application and all of them worked quite well. So I implemented one of them and everything was OK. Then one day I sent a bitmap attachment and when I clicked on Send the program went into a loop and stayed there for about an hour or so. That's when I realized that those encoders were only good for small binary attachments and completely fell apart when trying to encode large bitmaps. So I needed a better encoder. The attached zip file contains that encoder. It has a deblocker option on it in case you want to deblock your base64 encoded output. This was necessary because attachments on email had to be deblocked at 74 bytes per line.

    Download this and run it as a standalone. If you like it then use the .BAS module in your application.
    Attached Files Attached Files

  24. #24
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: JPEG, Base 64

    As far as I can see this is just another one of those "wheels" that doesn't need reinvention. WinNT OSs all have the CryptoAPI as part of the base install. You can use this as is, or via CAPICOM.

    CAPICOM is free and freely redistributable. Going that route also gets you support on Win9x with IE5+ installed.

    Of course playing with Base64 encoding by hand might be a decent programming excercise for a new VB programmer.

    The attached demo uses an internal Class to wrap the CryptoAPI calls, which means it doesn't run on Win9x but also doesn't have CAPICOM as a dependency. I don't know how it compares in speed with hand-rolled VB6 code but it's the code Windows uses all over the place itself.
    Attached Files Attached Files

  25. #25
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: JPEG, Base 64

    That's very good, dilettante. It was exactly the same as mine and the same time to encode it. So how would I go about deblocking it at different lengths?

  26. #26
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: JPEG, Base 64

    Quote Originally Posted by jmsrickland
    That's very good, dilettante. It was exactly the same as mine and the same time to encode it. So how would I go about deblocking it at different lengths?
    I'm not sure what you mean by "deblocking" here. Perhaps you are talking about line wrapping at varying lengths?

    I don't think you get an option here, the CryptoAPI library uses 64 characters. I think it uses that to conform to PEM (requires 64 character line length) and MIME (length is arbitrary but cannot exceed 76 character line length).

    Both of those limits come from SMTP quirks. Any Base64 decoder is expected to process any line length (including no wrapping at all). The line-wrap symbols can be either CrLf or Lf, and you have to handle both on decoding. It's all part of Postel's Law.


    I wasn't able to do much with your example. There are four missing non-standard typelibs. People also should be warned to stop using parts of the VB5 runtime in VB6 programs. Microsoft does not support VB5 after Windows XP and the runtimes aren't included in later OSs.

    You're also moving binary data around in String variables which is risky in some locales due to the Unicode translations. I'd have to think the double-conversion overhead would also be a performance killer when you encode and decode data that starts life as binary. Have you tried testing against actual binary data, such as an image file or an EXE?

    I'm getting encoding at under 0.02 secs/MB and decoding under 0.03 secs/MB even in the IDE. Of course this will vary based on your computer and almost all of the work is being done in the CryptoAPI library (Crypt32.dll) so compiling isn't an issue. This method is fast even if you compile for p-code to keep programs compact.

    Mine doesn't have any dependencies other than requiring an NT OS, so it is easy to test.
    Attached Files Attached Files

  27. #27

    Thread Starter
    Junior Member
    Join Date
    Sep 2007
    Posts
    17

    Re: JPEG, Base 64

    Quote Originally Posted by LaVolpe
    In what line? that would be helpful.
    What do you have in Text2? What does cdSave.FileName contain?
    In Text2.Text contain the encoded JPEG :

    /9j/4AAQSkZJRgABAQEAYABgAAD/4QA+RXhpZgAASUkqAAgAAAACAABRBAAEAAAAJgAAAAFR
    AwABAAAAAAADGQAAAAAHAAAABwAAAAcAAAAHAAAA/9sAQwAIBgYHBgUIBwcHCQkICgwUDQwL
    CwwZEhMPFB0aHx4dGhwcICQuJyAiLCMcHCg3KSwwMTQ0NB8nOT04MjwuMzQy/9sAQwEJCQkM
    CwwYDQ0YMiEcITIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIy
    MjIyMjIy/8AAEQgAMgAyAwEiAAIRAQMRAf/EAB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYH
    CAkKC//EALUQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEV
    UtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0
    dXZ3eHl6g4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV
    1tfY2drh4uPk5ebn6Onq8fLz9PX29/j5+v/EAB8BAAMBAQEBAQEBAQEAAAAAAAABAgMEBQYH
    CAkKC//EALURAAIBAgQEAwQHBQQEAAECdwABAgMRBAUhMQYSQVEHYXETIjKBCBRCkaGxwQkj
    M1LwFWJy0QoWJDThJfEXGBkaJicoKSo1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpz
    dHV2d3h5eoKDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT
    1NXW19jZ2uLj5OXm5+jp6vLz9PX29/j5+v/aAAwDAQACEQMRAD8A+f6KKmtbWW8nWGFCzMRk
    4JCjOMnHQc0m0ldlQhKclGKu2dL4U8L2Oq2suo6xqEdnp6uYFbzljcy4VgPmBGNpPvxWZ4l0
    P+wdUECTxz28yefbyI+7MRYhSTgDOB24rd/sqf8A4Q3+x98f2j+0PtW7J2bPL24zjOc+1Lrm
    j3mtT6LDZRl2hs4LKQ7SQrAkFzgHCDI5/SvKhiJKu5Sn7uunRJbM9nF5ZWw+EdSpS5VFXb/P
    7jiaK7j/AIVXrn/P1p3/AH8f/wCIrjr21ksL+4s5SpkglaJip4JUkHHtxXdRxVGu2qcr2Pms
    PjcPiG1RmnYgoooroOoK7HRtPlt7KO4hazgZ1DeReErdXAIB/cqB8yt0X1Oa46upg8QabNFZ
    XmoR3Y1XTYkishbqvkMI+Y/MydxO7OcY46VyYxTcUoo78vxH1eo5xdn0Nz7UnlbsN5m7Z5OP
    3nmf889v9/tt65q5o/iC20fUYzqVvdWbTkQqlwgjZQxHzkMRhODz7VyWja1HLrOoS3xVJL9Z
    PIfpHbXLsNsuSfkC8/MMkCpfEE8cOjR6feX0OqaqbgTi+hm88LDtK+V5h+YHdltvTnPevNnh
    FKXsprf+vwPZzXOZZlgamHkrRlFp+p3Nzb6Hc3U0/wDwnF7F5jl/Li1ZFRcnOFHYDsK8p1ZY
    01m+WK4a4jFxIFmZ95kG44Yt3J6571TorvwmDeHb9+/yR8NgcveFbfO5fJfoFFFFdx6IVsaf
    pNnceHtT1a8vZ4PsksNvDFDbCXzZJElZdxLrsX9yQSAx+bpxWPWppWsR6db3FvPpdpqME7o5
    jupZ1VWQMAQIpEBOHYZbOMnGMnIBqX3gPWbTVE06KDz5zL9nL70SN5TcyW6rGzN825omwCFb
    Cudu1S1Zf/CPamLeK4eCOKKR4EDSzxptMwcxb9zDYGWNmBbA24boyk9BpvjuaTXLTUtcaSc2
    TrdRpDGR9ouFunuQXAdVUkyzJv2sFVzhCear2ni86Xo1oLKW7OqC4glnmMkkWFgWaNEEiy72
    DRzBDt8rasYAByWoAx4/DmryWU161jJBaRJuM9yRCjZQSBVZyA7lGDBFyzA5AIrLrU1PXbnV
    bfyJkjVPttxfZDOzb5hGGBZ2YkDylwSSeTknNZdABRRRQAUUUUAFFFFABRRRQAUUUUAf/9kA
    If you convert it back here :

    http://www.motobit.com/util/base64-decoder-encoder.asp

    you will get the original file back.

    What does cdSave.FileName contain? <<< I can't really understand this. None I think.

  28. #28
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: JPEG, Base 64

    If Text2 is the base64 data, then simply do this. Remaining lines should be fine
    Code:
      REPLACE THESE 6 LINES 
            iFile = FreeFile()
            Open Text2.Text For Binary Access Read Lock Write As #iFile
            sJPG = String$(LOF(iFile), 0)
            Get #iFile, , sJPG
            Close #iFile
            sBase64 = myClass.Decode(sJPG)
    
    WITH JUST THIS ONE LINE
           sBase64 = myClass.Decode(Text2.Text)
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  29. #29

    Thread Starter
    Junior Member
    Join Date
    Sep 2007
    Posts
    17

    Re: JPEG, Base 64

    Thanks.. It works...

  30. #30
    New Member
    Join Date
    Aug 2008
    Posts
    2

    Re: JPEG, Base 64

    Hello!
    I'm trying bring the txt generated by the Encode to an object image. how can I do this?

    thanks

  31. #31
    New Member
    Join Date
    Aug 2008
    Posts
    2

    Re: JPEG, Base 64

    problem solved, thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width