Picture from url problem in Android

Hi,

The following code works perfectly in Desktop. But on Android it always returns NIL in Picture. I’ve noticed that the data doesn’t arrive exactly the same as in Desktop, some characters change or are missing.

var socket As New URLConnection
var url As String = “myurl/mypicture.png”

var data As String
data = socket.SendSync(“GET”, url, 10) ’ using synchronous GET

If socket.HTTPStatusCode = 200 Then ’ OK
’ Picture.FromData creates a new picture from raw binary data

var p As Picture
var rawData As String
rawData = DecodeBase64(data)

p = Picture.FromData(rawData)

ImageViewer1.Image = p
ImageViewer1.Refresh

Else ’ errors, redirects, etc.
MessageBox("Error : " + socket.HTTPStatusCode.ToString)

End If

Hi,
When writing code please use the </> button to wrap your code in a code block. It will be much easier to read.

Which version of Android are you using?
What size in KB is your picture?

There is a know bug in Xojo 2023r3 when sending data (misses one byte every 10 000 bytes).
Maybe this affects receiving data too.

Anyway, that bug is fixed in the latest 2023r4 pre-release.

Hi, i using the pre release r4 build 61716. The picture size is 2.2kb

It’s probably raw binary rather than Base64-encoded. Try deleting this line.

I have already tried this without success.

Maybe it’s being compressed by the server? Is the broken picture file the correct length? Are the first two bytes 1F 8B (the magic number for gzip compressed data)?

The same picture with the same URL in the same server with the same code work perfect in desktop project, the problem is in Android project, always return NIL on picture.FromData…