18

是否可以在 iOS 的 FMX 表单上放置 TImage 并将图像(jpg)从 URL 加载到此 TImage 中以显示在 iOS 应用程序中?

我试过没有成功。任何提示或指向正确的方向表示赞赏。

4

2 回答 2

2

将 TButton、TImageControl 和 TIdHttp 拖放到 Firemonkey 表单上,此代码将从 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;
于 2012-11-16T14:01:46.593 回答
0

答案有点冻结。我循环加载 4 张图像。当我按下按钮时,程序冻结下载图像,进度条不工作,如果下载继续完美。4 幅图像冻结 1 秒。对于 50,这是“无连接”或“错误程序”。这是代码。

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;
于 2014-04-11T18:56:26.263 回答