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

2

19

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.

Keeley answered 11/4, 2012 at 2:34 Comment(5)
It's hard to say what went wrong with this trivial task without seeing the code you wrote that failed.Backscratcher
Sorry Krom i may be wrong but at this time there isnt any comms objects in Firemonkey. I have searched there are many xcode examples but none for FMX.Keeley
any hints appreciated, just point me in right directionKeeley
Ah, so you mean specifically COM TImage? Why can't you use FMX TImage class?Backscratcher
i'm assuming that UIWebView is involved to retrieve a stream or something to then load into timage. Sorry for my ignorance but all this apple framework is very foreign to me.Keeley
A
3

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;
Aweless answered 16/11, 2012 at 14:1 Comment(0)
H
0

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;
Handout answered 11/4, 2014 at 18:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.