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

岁酱吖の 提交于 2019-12-05 10:30:56

问题


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.


回答1:


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;



回答2:


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;


来源:https://stackoverflow.com/questions/10099100/firemonkey-ios-rad-studio-xe2-display-image-on-form-loaded-from-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!