Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FireMonkey iOS RAD Studio XE2 - Display Image on form loaded from URL

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.

like image 289
ckglobalroaming Avatar asked Apr 11 '12 02:04

ckglobalroaming


1 Answers

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;
like image 133
sergeantKK Avatar answered Oct 13 '22 01:10

sergeantKK