How to add pictures to my app

CD Tom

Member
Licensed User
Longtime User
I've got my club app running finally. How much trouble would it be to add the club members photo to the app. On the main computer there is a folder with all club members photos they are identified by the club members number example would be 00184.jpg the problem is there are about 4500 photos and I don't know to get them loaded into a db where when the member is brought up on in the app that photo would show up.
If someone has some examples of how to do this I would appreciate looking at them.
Thanks for all your help.
 

pluton

Active Member
Licensed User
Longtime User
Will your app work online(connect to some database) or everything will be in the app?

It is better for you that you have photos numerical names:
example: John has ID number 00255 and his image is 00255.jpg :)
 
Upvote 0

pluton

Active Member
Licensed User
Longtime User
the photos will have to be in the app, and yes the photos are numbered 00321.jpg.

Ok here is a little idea.
Put all your image in app Files -> Add Files

Then in your app have one imageView in which will show your people picture

Some example:
B4X:
Sub Globals
   
   Dim i As Int 'here we store ID of John and later connect with ID of photo
   i = 0

   Dim picture As Bitmap ' picture will be loaded
   Dim imgView As ImageView 'place where will picture be shown
   
End Sub
Sub SomeWorkingCode
'.....some code
'...somelines of code example load John info
'...John is employe with ID: 007 so we put that ID in i

ID = i ' in this case 007

   picture= LoadBitmap(File.DirAssets, i&".jpg") 'this will be load picture 007.jpg from your app
   
   imgView.SetBackgroundImage(picture) 'this will set your picture in imgView
   
End Sub

This is short example how you can doit
 
Last edited:
Upvote 0

CD Tom

Member
Licensed User
Longtime User
Ok, I figured out how to load the files, if I would have looked before I asked I would have found it.
I have this working but do have another question. I clear the screen before I search for another member how do you clear the bitmap (picture)?
Thanks for your help once I see the code it sure becomes a lot easier.

PS What I did about the pictures was when I clear for the next search I just made the image visible = false and then when I loaded the picture I just made it true and everything is working great.

Again thanks for all your help.
 
Last edited:
Upvote 0

Beja

Expert
Licensed User
Longtime User
Thanks Pluton,
I also benefit from your sample code.. best was the comments!
to CD Tom, If you thought it is a good practice to maintain the imgbox for consistancy of UI, then you may consider creating a 'place-holder' img or olor-filled img, instead of hiding an showing the imgview.
 
Upvote 0

pluton

Active Member
Licensed User
Longtime User
Just a short tip.
Avoid naming images with first zero
example:
avoid like this naming: 007.jpg, 0025.jpg, 00036.jpg etc...

Name image like this: 7.jpg, 25.jpg, 36.jpg etc...

If your image already named like this there is still way to load it don't worry

You don't need to put ImageView1.Visible to false if there is no picture.
You can put default image for no photo. Look at this little code:

B4X:
Sub checkImage
   i = ID 'i is ID number example ID = 7 so i = 7
   'avoid naming photos like 007, 0012. Avoid start .jgg names with zero (0)
   
   If File.Exists(File.DirAssets, i&".jpg") Then 'check if image is in the app
   picture= LoadBitmap(File.DirAssets, i&".jpg") 'if true load picture
   ImageView1.SetBackgroundImage(picture) 'set picture in ImageView1
   ToastMessageShow("Photo loaded",False) ' just a toast message
   Else ' if image is not found in the app
   ImageView1.SetBackgroundImage(NoImagePhoto) 'load default image for NoPhoto
   ToastMessageShow("No photo for ID: " &i,False) 'just a little toast with info
   End If
End Sub

Images No1 (has photo) & Image No2 (no photo)

bond_loaded.png
image.png
 
Last edited:
Upvote 0

CD Tom

Member
Licensed User
Longtime User
That sounds like a better plan, I'll give that a try. Do you have any thoughts for a good way to keep the photo file up to date. Here's what happens once a month the club signs up new members at which time a photo is taken. I would like to be able to add those new photos to the app with out having to reload all the photos.
Also before I load all 4500 photos into the app is there a limit to how many files I can load?

Again thanks for all the help, this is a great forum.
 
Upvote 0

pluton

Active Member
Licensed User
Longtime User
You can put photos in separate folder on SD CARD or internal memmory of tablet/phone. Later just copy-paste new photos in that folder and the app will always take photos from that folder that you named it.

For example just made app that will search for photos on storage of tablet/phone in folder (Club_Photos)
And later you only need to update that folder. Not need to compile app every month and also put all 4500 images in the application.
The app will be small in size because photos are on storage in SD Card or internal storage of device

I would do that way. I also don't like to put that many photos in the application

The other way is online database so all data will be loaded from online database and pictures also
 
Upvote 0

CD Tom

Member
Licensed User
Longtime User
Ok that makes sense, with my test I only have a few photos loaded and I access then using dirAssets if I add the photos to the SD card in a folder how to I access the SD card? Is it with the DirRootExternal like
B4X:
picture = loadBitmap(File.DirRootExternal, "photofolder/id&".jpg")
or is it some other way.
 
Upvote 0

pluton

Active Member
Licensed User
Longtime User
Try like this asume that folder name is photofolder

B4X:
picture = loadBitmap(File.DirRootExternal, "photofolder/" &id&".jpg")
 
Upvote 0

CD Tom

Member
Licensed User
Longtime User
In loading photos to the SD card, I want the person using the app to be able to do this automatically. Can I zip up the photos and email that zip file to the person or persons using the app and then unzip it in the app when the save the zip file. I email the new members in a csv file and have a load new members button that will load the new members into the database. So I would like to do that with the photos. It would be nice to be able to zip up both the csv and the photos and only send one zip file.
Any ideas on how I can do that?

Thanks again
 
Upvote 0

androidtom

Member
Licensed User
Longtime User
similar app

I have a similar app I'm trying to develop but it's pictures of plants instead. The plant name, hybridizer, description and other text info is in an SQL database. When a particular name is searched and found, the data is presented on screen. I got this part sort of working with a few rough edges.

Now the task is to also show a picture but I'm not sure of how to include a few thousand pictures with the app. No picture is over 50K which is good so I've been following this thread looking for ideas. Everything is self contained - no online database. I'm going to try the SD directory of pictures idea which was presented here although I'm not sure how it would be initially populated by a user.
 
Upvote 0
Top