Recent

Author Topic: Android image gallery  (Read 1827 times)

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Android image gallery
« on: November 06, 2019, 03:08:11 pm »
Hi guys, can anyone tell me where to find an example to create a gallery of images? Let me explain: I have to show the thumbnails of the images belonging to the user in a screen So that then clicking on the thumbnail opens a full screen image. The full screen image I know how to do it, but the thumbnail list doesn't? Obviously I could have many thumbnails and have to scroll down to see them all.

« Last Edit: November 07, 2019, 04:10:45 pm by xinyiman »
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Image gallery
« Reply #1 on: November 06, 2019, 04:45:05 pm »

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: Image gallery
« Reply #2 on: November 07, 2019, 02:14:42 pm »
Hi wp, thanks for the reply, but it's not the same thing. I know how to do it with lazarus for pc, the problem is for android.
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Image gallery
« Reply #3 on: November 07, 2019, 03:11:57 pm »
Excuse me. I see now that you posted your question in the Android board and you provided all information required. But I normally look for new posts only in the "Recent" bar at the right, and there's nothing which gives me this kind of information. You could simply classification of your question if you'd mention "Android" also in the title, e.g. "Image Gallery for Android"

jmpessoa

  • Hero Member
  • *****
  • Posts: 2297
Re: Android image gallery
« Reply #4 on: November 07, 2019, 11:49:31 pm »
Hi, xinyiman!

At the moment, you can try the:

GetResizedBitmap(....)     from  jBitmap component....

[edited]

you can try jViewFlipper component, too:

Adjust it to a "thumbnails"  size  and  try:

jViewFlipper1. AddView(.....)   

« Last Edit: November 08, 2019, 12:07:36 am by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: Android image gallery
« Reply #5 on: November 08, 2019, 11:17:46 am »
Hi jmpessoa, thanks for the reply. Using GetResizedBitmap I can resize the image. But I can't get the components to display at run time. I created a small function, which does not go wrong, but does not show anything on the screen. Can you tell me what's wrong?

For global declaration
Code: Pascal  [Select][+][-]
  1. type
  2.  
  3.   { TAndroidModule1 }
  4.  
  5.   TAndroidModule1 = class(jForm)
  6.     jButton1: jButton;
  7.     jImageList1: jImageList;
  8.     jScrollView1: jScrollView;
  9.     jSpinner1: jSpinner;
  10.     procedure jButton1Click(Sender: TObject);
  11.   private
  12.     {private declarations}
  13.     GalleryImages : array of jImageView;
  14.     GalleryBmp    : array of jBitmap;
  15.     procedure CreateGallery;
  16.     procedure ClickMiniatura(Sender: TObject);
  17.   public
  18.     {public declarations}
  19.   end;        
  20.  

My procedure to create a runtime the image gallery
Code: Pascal  [Select][+][-]
  1. procedure TAndroidModule1.CreateGallery;
  2. var
  3.    i             : integer;
  4.    //top           : integer;
  5.    //left          : integer;
  6.    num_col       : integer;
  7.    space_col     : integer;
  8. begin
  9.      num_col   := 3;
  10.      space_col := 4;
  11.      //top       := 0;
  12.      //left      := 0;
  13.  
  14.      for i := 0 to Length(GalleryBmp)-1 do
  15.      begin
  16.           GalleryBmp[i].Free;
  17.           GalleryBmp[i] := nil;
  18.  
  19.           GalleryImages[i].Free;
  20.           GalleryImages[i] := nil;
  21.      end;
  22.  
  23.      SetLength(GalleryBmp,0);
  24.      SetLength(GalleryImages,0);
  25.  
  26.      for i:=0 to Self.jImageList1.Count-1 do
  27.      begin
  28.           SetLength(GalleryBmp, Length(GalleryBmp)+1);
  29.           GalleryBmp[Length(GalleryBmp)-1]                  := jBitmap.Create(Self);
  30.           GalleryBmp[Length(GalleryBmp)-1].Name             := 'jBitmap' + IntToStr(i+1);
  31.           GalleryBmp[Length(GalleryBmp)-1].Images           := Self.jImageList1;
  32.           GalleryBmp[Length(GalleryBmp)-1].ImageIndex       := i;
  33.  
  34.  
  35.           SetLength(GalleryImages, Length(GalleryImages)+1);
  36.           GalleryImages[Length(GalleryImages)-1]                := jImageView.Create(Self.jScrollView1);
  37.           GalleryImages[Length(GalleryImages)-1].Name           := 'jImageView' + IntToStr(i+1);
  38.           GalleryImages[Length(GalleryImages)-1].Parent         := Self.jScrollView1;
  39.           //GalleryImages[Length(GalleryImages)-1].Top            := top;
  40.           //GalleryImages[Length(GalleryImages)-1].Left           := left;
  41.  
  42.           if i > 0 then
  43.           begin
  44.                GalleryImages[Length(GalleryImages)-1].Anchor              := GalleryImages[Length(GalleryImages)-2];
  45.  
  46.                if ((i mod num_col) = 0) and (i>0) then
  47.                begin
  48.                     GalleryImages[Length(GalleryImages)-1].PosRelativeToAnchor := [raBelow];
  49.                     GalleryImages[Length(GalleryImages)-1].PosRelativeToParent :=[rpLeft];
  50.                end else begin
  51.                     GalleryImages[Length(GalleryImages)-1].PosRelativeToAnchor := [raAlignBaseLine];
  52.                end;
  53.           end else begin
  54.                GalleryImages[Length(GalleryImages)-1].PosRelativeToParent :=[rpTop, rpLeft];
  55.           end;
  56.  
  57.  
  58.           GalleryImages[Length(GalleryImages)-1].Width          := Trunc(Self.jScrollView1.Width / num_col);
  59.           GalleryImages[Length(GalleryImages)-1].Height         := GalleryImages[Length(GalleryImages)-1].Width;
  60.  
  61.           GalleryImages[Length(GalleryImages)-1].ImageScaleType := scaleCenter;
  62.           GalleryImages[Length(GalleryImages)-1].Enabled        := true;
  63.           GalleryImages[Length(GalleryImages)-1].Visible        := true;
  64.  
  65.           //GalleryImages[Length(GalleryImages)-1].Tag            := i;
  66.           //GalleryImages[Length(GalleryImages)-1].OnClick        := ClickMiniatura;
  67.  
  68.           GalleryImages[Length(GalleryImages)-1].SetImageBitmap(GalleryBmp[Length(GalleryBmp)-1].GetResizedBitmap(GalleryImages[Length(GalleryImages)-1].Width, GalleryImages[Length(GalleryImages)-1].Height));
  69.  
  70.           GalleryImages[Length(GalleryImages)-1].Refresh;
  71.           GalleryImages[Length(GalleryImages)-1].Invalidate;
  72.  
  73.           {if ((i mod num_col) = 0) and (i>0) then
  74.           begin
  75.                left := 0;
  76.                top  := top + GalleryImages[Length(GalleryImages)-1].Height + space_col;
  77.           end else begin
  78.                left := left + GalleryImages[Length(GalleryImages)-1].Width + space_col;
  79.           end;}
  80.  
  81.      end;
  82.  
  83.      Self.jScrollView1.Invalidate;
  84. end;
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

jmpessoa

  • Hero Member
  • *****
  • Posts: 2297
Re: Android image gallery
« Reply #6 on: November 09, 2019, 05:30:19 pm »
You can try:

GalleryBmp[Length(GalleryBmp)-1]:= jBitmap.Create(Self);
GalleryBmp[Length(GalleryBmp)-1].Init(gApp);     //or after some configs.....???

GalleryImages[Length(GalleryImages)-1]:= jImageView.Create(Self);  //try "self" here ....
GalleryImages[Length(GalleryImages)-1].Init(gApp)  ////or after some configs.....???


Good news!

I am doing a new demo to help your!
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

jmpessoa

  • Hero Member
  • *****
  • Posts: 2297
Re: Android image gallery
« Reply #7 on: November 11, 2019, 05:43:27 am »
Hi, xinyiman!

You  can try new demo  [GUI]   "AppScrollingImages"

[update your LAMW from github!]

Thank you!
« Last Edit: November 11, 2019, 05:48:07 am by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: Android image gallery
« Reply #8 on: November 11, 2019, 08:06:33 am »
Hi, thank you very much. Today I try it and let you know.
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: Android image gallery
« Reply #9 on: November 12, 2019, 08:52:19 am »
Your demo run correctly. Thank you very much
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

 

TinyPortal © 2005-2018