Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
4
Erster Beitrag:
vor 2 Jahren, 6 Monaten
Letzter Beitrag:
vor 2 Jahren, 6 Monaten
Beteiligte Autoren:
CCC2, Danny Lauwers

Converting Json data to image

Startbeitrag von CCC2 am 25.08.2015 05: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.

Antworten:

doesn't work fully on WM20 - android , the picture show as distorted picture .

any idea , why?

von CCC2 - am 25.08.2015 07:23
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

von Danny Lauwers - am 25.08.2015 07:50
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

von CCC2 - am 25.08.2015 10:35
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.