PC SOFT

FOROS PROFESIONALES
WINDEVWEBDEV y WINDEV Mobile

Inicio → WINDEV 2024 → Converting Json data to image
Converting Json data to image
Iniciado por guest, 25,ago. 2015 07:58 - 3 respuestas
Publicado el 25,agosto 2015 - 07:58
if your json image data in this format
"img":[255,216,255,224,0,16,74,70, ... ]

to convert ?
1. take out the number with in the braket "[]" .
2. extract each number into array
StringToArray(My_string , My_Array, ",")
3. convert each number in array into ascii character
FOR my_cnt =1 TO Dimension((My_Array))
My_Array[my_cnt] = Charact(My_Array[my_cnt])
END
4. convert it back into string
My_buf = ArrayToString(My_Array,"")

if your application is unicode ON , make sure to convert it to ansi or the image won't display .
M_buf = UnicodeToAnsi(ArrayToString(M_Array,""))

when unicode is ON ArrayToString() create more , using length(my_buf) you will notice the length different between ansi and unicode mode.
Publicado el 25,agosto 2015 - 09:23
doesn't work fully on WM20 - android , the picture show as distorted picture .

any idea , why?
Publicado el 25,agosto 2015 - 09:50
Hi,

From the top of my head:
You can use deserialize to get the JSON Array into an array of bytes, this would be much faster the looping it yourself.
Then you could transfer the bytes to your picture

The JSON structure to be used to deserialize it (Android does not support Variants yet :-(

STjsondata is Structure img is array of bytes END
PROCEDURE test(sData is ANSI string) stMydata is STjsondata Deserialize(stMydata,sData,psdJSON) // You can put this in a buffer or image or process it further like you wish, depends on the content of the data Mybuf is Buffer picture is Image Mybuf = stMydata.img picture = Mybuf
It ofcourse depends on how the image is transferred.

If you have control on how you send the picture:
In most cases the image to transfer via REST is converted into base64

sBase64String = Crypt(bufImageBuffer ,"",cryptNone,True)
And then send to the client. The client will convert this string back to a buffer/image

Hope you get it working !
Have a nice day
Danny
Publicado el 25,agosto 2015 - 12:35
Hi Danny,

Thanks for the suggestion . i will try later.

I found out why the image distorted in WM20-android . i suspect UnicodeToAnsi() is not working corretly in WM20-android . some of the character endup as different character .

I generate out as file and did file compare . comparing the hex , i see few character change.

in Hexadecimal -> 81 , 8D, 9D, 8F, 90