B4J Question Json BLOB to Image File Cluelessness

mmieher

Active Member
Licensed User
Longtime User
I am trying to recover thousands of personally valuable very old images that are stored in this mummified software titled PhotoRecall DELUXE, which stored the bmp(?) images in an Access 97 .mdb file. I cannot find the original software.

As usual, I do not know the correct keyword to search for.

I have gotten to a Json dump of the mdb relic with a tool I found. Here is the first abbreviated record:
B4X:
{"$binary": "/9j/4AAQSkZJRgABAAEAlgCWAAD//gAfTEVBRCBUZ   THIS GOES ON AND ON  87414 BYTES    lSRdynOGA==", "$type": "00"}

I have been trying things shown below. All this byte, bit, char, array stuff continues to confound me. I usually rely on a code-snippet from one of you to accomplish whatever.

B4X:
    Dim DIR As String = File.DirData("PhotoExport")
    Dim fn As String = "b4jtest.bmp"
   
    Dim parser As JSONParser
    parser.Initialize(Json)
    
    Dim jRoot As Map = parser.NextObject
    Dim jType As String = jRoot.Get("$type")
    Log("jType = " & jType)
    
    ''Dim binary As Object = jRoot.Get("$binary")
    Dim strBinary As String = jRoot.Get("$binary")
   
    Dim bc As ByteConverter
    'bc.LittleEndian = True
    Dim Buffer() As Byte = bc.StringToBytes(strBinary, "UTF8" )   ' <--- this cannot be right
    
    
'    Dim out As OutputStream = File.OpenOutput(DIR,fn,False)
'    out.InitializeToBytesArray(0)
'    Log("Buffer.Length = " & Buffer.Length)
'    out.WriteBytes( Buffer , 0, Buffer.Length)
'    'out.Flush
'    out.Close

    File.WriteBytes(DIR,fn, Buffer)
    
    Log("*** wrote bytes")

I end up with a ".bmp" file with a byte size that is darn close to correct, but definitely does not qualify on any planet as an "image".

I want to end up with a usable anything. These photos were taken with what might have been the first "modern" Sony camera thing. You needed to insert a 3.5" diskette, which would hold about six pictures at "extreme high quality". But they are the entire photographic record of my life before thirty, and The Rents life before me.
 
Solution
You could just go into the Chrome dev tools and insert a tag anywhere like this to see if it shows something:

B4X:
<img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAAEAlgCWAAD//gAfTEVBRCBUZ........">

or

<img src="data:image/png;base64,/9j/4AAQSkZJRgABAAEAlgCWAAD//gAfTEVBRCBUZ........">

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
Dim bc As ByteConverter 'bc.LittleEndian = True Dim Buffer() As Byte = bc.StringToBytes(strBinary, "UTF8" )
it seems this are stored in Base64 so use StringUtils
B4X:
dim su as stringutils
dim by  as byte() = su.decodebase64(strBinary)
 
Upvote 0

mmieher

Active Member
Licensed User
Longtime User
it seems this are stored in Base64 so use StringUtils
B4X:
dim su as stringutils
dim by  as byte() = su.decodebase64(strBinary)
Thanks, Enrique.

Still do not have usable image.
B4X:
Dim parser As JSONParser
    parser.Initialize(Json)
    
    Dim jRoot As Map = parser.NextObject
    Dim jType As String = jRoot.Get("$type")
    Log("jType = " & jType)
    
    Dim strBinary As String = jRoot.Get("$binary")
    
    Dim su As StringUtils
    
    Dim by() As Byte
    by = su.DecodeBase64(strBinary)

    File.WriteBytes(DIR,fn, by)
    
    Log("*** wrote bytes")

B4X:
Waiting for debugger to connect...
Program started.
AppStart
SUB  HandleSimpleJsonObject:  rCount = 1
Json.length = 57362
jType = 00
*** wrote bytes

The .bmp file ends up being 42997 bytes.
 
Upvote 0

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
Are you sure this are BMP and not PNG or jpg? I am sure it is b64 as the encoding always ends with a =

If it still doesn't work. Are you sure it is not encrypted ??
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
I think base64 doesn't contain slash (/). Try split the string and take the longest one (I think the last part) to decode.

I was wrong. base64 does contain slash.

Try use this website to decode.

 
Upvote 0

mmieher

Active Member
Licensed User
Longtime User
Upvote 0

emexes

Expert
Licensed User
which stored the bmp(?) images in an Access 97 .mdb file.
B4X:
{"$binary": "/9j/4AAQSkZJRgABAAEAlgCWAAD//gAfTEVBRCBUZ   THIS GOES ON AND ON  87414 BYTES    lSRdynOGA==", "$type": "00"}

Your limited sample decodes to looking like a JPEG file.

�JFIF�������LEAD T
 
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
You could just go into the Chrome dev tools and insert a tag anywhere like this to see if it shows something:

B4X:
<img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAAEAlgCWAAD//gAfTEVBRCBUZ........">

or

<img src="data:image/png;base64,/9j/4AAQSkZJRgABAAEAlgCWAAD//gAfTEVBRCBUZ........">
 
Upvote 0
Solution

mmieher

Active Member
Licensed User
Longtime User
Thank you for your help everyone.

I am going to first try @alwaysbusy solution because I know he is probably correct. The source is almost a gig so I need to cut out a record or two.

Regarding the file type, these photos have a few "cousins" that I do have on disk. They are .bmp files. My wrecked memory cells vaguely recall .bmp files moving from the diskette to Windows 1. That means nothing.

Regarding the data upload, I knew it would come to this. The thing is, I know these images are from the 1980's and 1990's. I do not know what they are pictures of. It could be almost anything.

This could either be fun, or an absolutely horrible experience. What to do?

[post edit]
I am now recalling that those cousins where created using the unavailable software's EXPORT function. I probably chose ".BMP" because I did not know what anything else was. If there was anything else.
 
Upvote 0

mmieher

Active Member
Licensed User
Longtime User
Ok.

Here are three images from the time capsule.

Fear nothing, Amigos!
 

Attachments

  • unknown-images-for-The-Forum.json.txt
    155.2 KB · Views: 143
Upvote 0

mmieher

Active Member
Licensed User
Longtime User
For both png and jpeg THE GOOG dev tools when hovering over code in Elements window, shows a white rectangle with purple font "img" and grayish "16 X 16". Nothing in the preview side.

1675801403570.png
 
Last edited:
Upvote 0

mmieher

Active Member
Licensed User
Longtime User
Are you sure this are BMP and not PNG or jpg? I am sure it is b64 as the encoding always ends with a =

If it still doesn't work. Are you sure it is not encrypted ??
I sure hope it is not encrypted. It would needed to be the default because I did not know what the word "encrypted" meant in the 80's. The computer term I mean.
 
Upvote 0

mmieher

Active Member
Licensed User
Longtime User
I think base64 doesn't contain slash (/). Try split the string and take the longest one (I think the last part) to decode.

I was wrong. base64 does contain slash.

Try use this website to decode.

What do I do with the result? The result has lots of "crazy" characters.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
and in b4a

grad.png
 
Upvote 0
Top