wwLayoutGrid show photos located in URLs

113 views
Skip to first unread message

Vicente Cifre

unread,
Apr 24, 2016, 5:34:59 PM4/24/16
to woll2woll.infopower
Hi,

I have upgraded to the latest version Firepower 6.1.1.12.
I'm using Delphi Seattle.
In my project, I tried using the wwLayoutGrid component to display information regarding properties (similar to House Photos included in your demo).
Each property includes a photo that I need to show with data along with housing (rooms, price, etc ...)
My problem is that the photographs are not stored fields of the database, they are located in a web address (http://www.webphotos.es/photos/photoxxx.jpg).
Although I have done several tests, I can't found the correct and more efficient procedure for get that when the wwLayoutGrid component is loaded the wwImageControl show the linked photographs. I tested with different events of wwLayoutGrid (Onpainting, OnCustomDrawControl, etc ...), but all I've got is that in some cases, executing on windows, picture is displayed when the row takes focus, but  always when I execute in Android application crashes or is blank.

I have two questions:

A) What would be the event or procedure correct to get to load every photograph ?
B) I tryied using a stream how you can see in the next procedure, but I would like to know if there are other method more efficient.

This is the code I use to load the picture (called from an event of wwLayoudGrid).

TForm2.Chargefoto procedure (cfoto: string; Imagex: TImage);
 var MS: TMemoryStream;
     URL: string;
     I: integer;
begin

  MS: = TMemoryStream.Create;

    try
      for i: = 1 to 1 do
      begin

        URL: = 'http://www.webphotos.es/photos/' + cfoto;

        MS.Clear;

        IdHTTP1.Get (URL, MS);

        MS.Seek (0, soFromBeginning);
        Imagex.bitmap.LoadFromStream (MS);
     end;
      finally
          MS.Free;

         end;
     Application.ProcessMessages;

end;

Thanks for your help.

Vicens

roy....@gmail.com

unread,
Apr 24, 2016, 10:27:38 PM4/24/16
to Vicente Cifre, woll2woll...@googlegroups.com
To load every photograph, you could use your form’s OnShow event. See our demo’s OnFormShow event which has commented code that would put the photos into an SQLite database.  You don’t even need to do this, if you just want to keep the bitmaps in memory, but this will consume more system resources. You will still need to use the OnCustomDrawControl event to load the bitmap. See the next paragraph for how to do this.

If you want to load photos one at a time, then it will transition a little slower, but it will startup faster and use less resources.  I recommend this approach. To have them load when you move to a new page, you can use the OnCustomDrawControl event. For example change our demo to be like the following. Add the unit idhttp to your form’s uses clause to resolve the TidHttp indy reference. Note, you may want to set TransitionSettings.ShowWaitIndicator to true if the bitmaps take a little time to load from the web. After changing the code, the bitmap displayed is the one from the web, not the one in the database.

// Download bitmap from url
function DownloadBitmap(uri: String; bm: TBitmap): Boolean;
var
  s: TStream;
begin
  Result := False;
  s := TMemoryStream.Create;
  with TIdHTTP.Create(nil) do
  try
    Get(uri, s);
    s.Position:= 0;
    bm.LoadFromStream(s);
    Result := True;
  finally
    Free;
    s.Free;
  end;
end;

procedure THousePhotosForm.lgImagesCustomDrawControl(Sender: TObject;
  CellAttributes: TwwCustomDrawControlAttributes);
var fileName: string;
   bm: Tbitmap;
begin
  if cellattributes.Control = lblRecNo then
  begin
    tlabel(cellattributes.CloneControl).Text:= cellattributes.GetValue('ID').ToString +
       ' of ' + inttostr(lgImages.RecordCount);
  end
  else if cellAttributes.Control = icHomePicture then // Loads from web address instead
  begin
    // load bitmaps from Woll2Woll Server
    fileName:= 'http://ec2-54-215-239-17.us-west-1.compute.amazonaws.com/downloads/Photos/Home/' +
      cellAttributes.GetValue('Location').ToString + '.jpg';
    fileName:= filename.Replace(' ', '');
    bm:= TBitmap.Create;
    DownloadBitmap(filename, bm); // if url
    TwwImageControl(CellAttributes.CloneControl).Bitmap.Assign(bm);
    bm.Free;
  end;

end;

-Roy Woll

--
You received this message because you are subscribed to the Google Groups "woll2woll.infopower" group.
To unsubscribe from this group and stop receiving emails from it, send an email to woll2wollinfopo...@googlegroups.com.
Visit this group at https://groups.google.com/group/woll2wollinfopower.
To view this discussion on the web visit https://groups.google.com/d/msgid/woll2wollinfopower/b493fc67-f006-49ec-81ae-5eec645b9dec%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Vicente Cifre

unread,
Apr 25, 2016, 1:34:54 PM4/25/16
to woll2woll.infopower

I will try the options commented.

Thanks for your help.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages