I've been working on a simple Firemonkey app in Berlin 10.1 to load an image from a web service using IdHttp.Get() into a memory stream and then loading that into the a TBitmap. It works great on iOS and Windows but on Android it seems to fail on img.LoadFromStream().

I've been working on a simple Firemonkey app in Berlin 10.1 to load an image from a web service using IdHttp.Get() into a memory stream and then loading that into the a TBitmap. It works great on iOS and Windows but on Android it seems to fail on img.LoadFromStream().
It isn't raising an error, it's just not going any further but that might be a debugger issue (I've had a few with Berlin).
Does anyone know of problems doing this on Android or is there something I'm not setting/converting/encoding properly?

Thanks

The code is:
task:=TTask.Create(
procedure ()
var
ms: TMemoryStream;
png: FMX.Graphics.TBitmap;
http: TIdHttp;
begin
png:=nil;
http:=TIdHTTP.Create(nil);
ms:=TMemoryStream.Create;
try
try
ms.Clear;
http.Get(url, ms);

ms.Position:=0;
png:=TBitmap.Create;
png.LoadFromStream(ms);

if fBannerImage = nil then
fBannerImage:=TBitmap.Create;

fBannerImage.Assign(png);

TThread.Synchronize(
nil,
procedure ()
begin
if Assigned(onComplete) then
onComplete();
end);
except
on E: Exception do
Log('Error loading bitmap - '+e.Message);
end;
finally
ms.Free;
http.free;
if Assigned(png) then
png.Free;
end;
end);

task.Start;

Comments

  1. David Berneda
    Fortunately, this bug has been fixed in recent versions

    Here the problem is the use of a bitmap in a secondary thread, do as Michael says

    ReplyDelete
  2. That's brilliant, thanks everyone! I normally do this synchronously which explains why I've never had this before

    ReplyDelete

Post a Comment