Recent

Author Topic: jListView with image  (Read 448 times)

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
jListView with image
« on: April 06, 2023, 04:05:27 pm »
Someone explain to me how to put in a listview an image (loaded at runtime retrieved from a record in sqlite) aligned left and the text in the center.
I need it to be able to preview a series of products combined with their name. A thousand thanks
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

jmpessoa

  • Hero Member
  • *****
  • Posts: 2302
Re: jListView with image
« Reply #1 on: April 06, 2023, 04:35:59 pm »
Hi, xinyiman!

If you can retrieve the image from a record in sqlite....

then you can try some code like theses [events]:

Code: Pascal  [Select][+][-]
  1. procedure TAndroidModule1.ListView1DrawItemBitmap(Sender: TObject;
  2.   itemIndex: integer; itemCaption: string; out bimap: JObject);
  3. begin
  4.   if itemIndex = 1 then   //only item index = 1 has a image ...
  5.   begin
  6.     bimap:= ImageFileManager1.LoadThumbnailFromAssets('lemur_funny.png', 72, 72);
  7.   end;
  8. end;
  9.  

or

Code: Pascal  [Select][+][-]
  1. procedure TAndroidModule1.ListView1DrawItemWidgetBitmap(Sender: TObject;
  2.   itemIndex: integer; widgetText: string; out bimap: JObject);
  3. begin
  4.   if itemIndex = 1 then   //only item index = 1 has a image ...
  5.   begin
  6.     bimap:= ImageFileManager1.LoadThumbnailFromAssets('lemur_funny.png', 72, 72);
  7.   end;
  8. end;  
  9.  
« Last Edit: April 06, 2023, 04:37:37 pm by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: jListView with image
« Reply #2 on: April 06, 2023, 04:49:44 pm »
I was thinking of saving images in base64 in text field. How do I then convert them to bitmaps?
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

jmpessoa

  • Hero Member
  • *****
  • Posts: 2302
Re: jListView with image
« Reply #3 on: April 06, 2023, 05:21:44 pm »

You can try "jBitmap component" methods:

Code: Pascal  [Select][+][-]
  1.     function GetBase64StringFromImage(_bitmap: jObject; _compressFormat: TBitmapCompressFormat): string;
  2.     function GetBase64StringFromImageFile(_fullPathToImageFile: string): string;
  3.  
  4.     function GetImageFromBase64String(_imageBase64String: string): jObject;  // <-- try this!
  5.  
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

 

TinyPortal © 2005-2018