Is it possible to place a TImage on an FMX form for iOS and load image (jpg) from an URL into this TImage to be displayed in the iOS app?
I have tried with no success. Any hints or point in the right direction is appreciated.
Is it possible to place a TImage on an FMX form for iOS and load image (jpg) from an URL into this TImage to be displayed in the iOS app?
I have tried with no success. Any hints or point in the right direction is appreciated.
Drop a TButton, TImageControl and TIdHttp onto a Firemonkey form and this code will pull down an image from the web:
procedure TForm1.btnReadWebImgClick(Sender: TObject);
begin
ReadWebImage('http://www.gravatar.com/avatar/5af5f8c5f88c6c237745e9472a31410f?s=32&d=identicon&r=PG');
end;
procedure TForm1.ReadWebImage(imgAddress: string);
var
memStream: TMemoryStream;
begin
memStream := TMemoryStream.Create;
try
idhttp1.Get (imgAddress,memStream);
except
ShowMessage('Image not found at:'+imgAddress);
memStream.Free;
exit;
end;
try
memStream.Position := 0;
ImageControl1.Bitmap.LoadFromStream(memStream);
finally
memStream.Free;
end;
end;
The answer works with a little freezing. I load 4 images in a loop. When I push the button, the program freeze to download the images, the progress bar not working and if are downloaded continue perfectly. For 4 images freeze for 1 sec. For 50 it's a "no connection" or "Bad Program". This is the code.
procedure TForm1.SpeedButton1Click(Sender: TObject);
var
i: Integer;
Stream: TMemoryStream;
imgAddress: string;
begin
ProgressBar1.Min := 0;
ProgressBar1.Max := Table1.RecordCount;
for i := 1 to Table1.RecordCount do
begin
ProgressBar1.Value := i;
imgAddress := VirtualTable1.FieldByName('flyer').AsString;
Stream := TMemoryStream.Create;
idhttp1.Get (imgAddress,Stream);
try
Stream.Position := 0;
Table1.Edit;
TBlobField(Table1.FieldByName('image')).LoadFromStream(Stream);
Table1.Post;
finally
Stream.Free;
end;
Table1.Next;
end;
Table1.First;
end;
© 2022 - 2024 — McMap. All rights reserved.