Recent

Author Topic: [Solved] Background Image  (Read 1045 times)

higgins

  • New member
  • *
  • Posts: 6
[Solved] Background Image
« on: February 16, 2023, 03:36:34 pm »
Hi there,

I try to set a background image using  jImageView on which i set layoutParamHeight and layoutParamWidth properties to lpMatchParent but, i encounter issues

Method #1: using jImageList

I add my picture to the jImagelist and set  ImageList and  Imageindex properties of the JImageView component: it works fine
My problem is that i need a second jImageList to store icons for buttons  (all pictures in an jImageList need to have the same size) and there is the issue: whatever jImageList i handle, the pictures are  "mixed" between the two jImagelist components, with different sizes and, so, cannot be accessed by the  Imageindex property.
every change on one jImagelist component affects the other too  :o

How can i use more than one jImagelist in the application?

So, I tried method #2: using resources
I added to the project'sresources a bitmap file named background.bmp , I named the resource BACKGROUND
and i added the following code to the onCreate Event
Code: Pascal  [Select][+][-]
  1. procedure TAndroidModule1.AndroidModule1Create(Sender: TObject);
  2.  
  3.   var bmp:jBitmap;
  4. begin
  5.    bmp:=jBitmap.create(self);
  6.    bmp.LoadFromRes('BACKGROUND');
  7.    imageview1.SetImageBitmap(bmp);
  8.  
  9. end;
  10.  
Issue: The picture is not loaded
could anyone help me please?
« Last Edit: March 02, 2023, 10:54:59 am by higgins »

jmpessoa

  • Hero Member
  • *****
  • Posts: 2249
Re: Background Image
« Reply #1 on: February 20, 2023, 10:15:34 pm »
Hi, higgins!

Get a  jBitmap component from component tabs [Android Bridge]

No "create" is need... just use it!
« Last Edit: February 24, 2023, 11:59:25 pm by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

higgins

  • New member
  • *
  • Posts: 6
Re: Background Image
« Reply #2 on: February 22, 2023, 09:38:23 am »
Hi,

Thank you for your help.
I don't really understand why using a jBitmap from the tab may have a different behaviour than creating it by code.
Indeed, the result is the same for me, the form remains blank on my phone.

This is my code
Project:
Code: Pascal  [Select][+][-]
  1. {hint: Pascal files location: ...\AppLAMWProject16\jni }
  2. library controls;  //[by LAMW: Lazarus Android Module Wizard: 22/02/2023 08:38:16]
  3.  
  4. {$mode delphi}
  5.  
  6. uses
  7.   {$IFDEF UNIX}{$IFDEF UseCThreads}
  8.   cthreads,
  9.   {$ENDIF}{$ENDIF}
  10.   Classes, SysUtils, And_jni, And_jni_Bridge, AndroidWidget, Laz_And_Controls,
  11.   Laz_And_Controls_Events, unit1;
  12.  
  13. {%region /fold 'LAMW generated code'}  
  14.  
  15. {$R *.res}
  16.  
  17. begin
  18.   gApp:= jApp.Create(nil);
  19.   gApp.Title:= 'LAMW JNI Android Bridges Library';
  20.   gjAppName:= 'org.lamw.applamwproject16';
  21.   gjClassName:= 'org/lamw/applamwproject16/Controls';
  22.   gApp.AppName:=gjAppName;
  23.   gApp.ClassName:=gjClassName;
  24.   gApp.Initialize;
  25.   gApp.CreateForm(TAndroidModule1, AndroidModule1);
  26. end.                
  27.  
AndroidModule:
Code: Pascal  [Select][+][-]
  1. uses
  2.   {$IFDEF UNIX}{$IFDEF UseCThreads}
  3.   cthreads,
  4.   {$ENDIF}{$ENDIF}
  5.   Classes, SysUtils, AndroidWidget, Laz_And_Controls;
  6.  
  7. type
  8.  
  9.   { TAndroidModule1 }
  10.  
  11.   TAndroidModule1 = class(jForm)
  12.     Bitmap1: jBitmap;
  13.     ImageView1: jImageView;
  14.     procedure AndroidModule1Create(Sender: TObject);
  15.   private
  16.     {private declarations}
  17.   public
  18.     {public declarations}
  19.   end;
  20.  
  21. var
  22.   AndroidModule1: TAndroidModule1;
  23.  
  24. implementation
  25.  
  26. {$R *.lfm}
  27.  
  28.  
  29. { TAndroidModule1 }
  30.  
  31. procedure TAndroidModule1.AndroidModule1Create(Sender: TObject);
  32. begin
  33.    Bitmap1.LoadFromRes('BACKGROUND');
  34.    imageview1.SetImageBitmap(Bitmap1);
  35. end;
  36.  
  37. end.              
  38.  


Regarding the jIMageList, issue, do you have a clue? When searching through the forum to find informations about that, i found a topic posted in march 2021 about this
https://forum.lazarus.freepascal.org/index.php/topic,53684.msg397892.html#msg397892 any informations about that?

jmpessoa

  • Hero Member
  • *****
  • Posts: 2249
Re: Background Image
« Reply #3 on: February 24, 2023, 11:59:10 pm »
Code: Pascal  [Select][+][-]
  1. imageview1.SetImageBitmap(Bitmap1);       // No!
  2.  

use as:

Code: Pascal  [Select][+][-]
  1. imageview1.SetImageBitmap(Bitmap1.GetImage());       // Yes!
  2.  
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

higgins

  • New member
  • *
  • Posts: 6
Re: Background Image
« Reply #4 on: February 27, 2023, 11:41:14 am »
Thanks for you help.
Actually, i noticed that the resource i added in project's options doesn't exist in the application
a call to "Findresource(hinstance,'BACKGROUND','BITMAP') returns 0
Do i need to set additional options to include the resource in the application?

jmpessoa

  • Hero Member
  • *****
  • Posts: 2249
Re: Background Image
« Reply #5 on: February 28, 2023, 06:32:48 pm »

Put your image in project folder  ..../res/drawable
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

higgins

  • New member
  • *
  • Posts: 6
Re: Background Image
« Reply #6 on: March 02, 2023, 10:54:17 am »
Indeed, this doesn't work much more  :(
I also tried to copy the file in ../assets to use "Bitmap1.loadfromfilename('background.bmp')" or "Bitmap1.loadfromassets('background.bmp') without success
At last it works with copying the picture in ..../res/drawable as you suggested then in Android module, set backgroundimageidentifier property to 'background"

 

TinyPortal © 2005-2018