Android Question Not able to pass an image name from a list to an imageview via a bitmap initialization.

PhilMac

Member
Licensed User
Longtime User
For i= 0 To 74
Dim imvImage As ImageView
Dim bmpImage As Bitmap
Dim ImageName As String
ImageList.Sort(True)
bmpImage.Initialize(File.DirAssets,"""&ImageList.Get(i)&""") 'ImageList.Get(i)) ' "image"&i&".jpg")
imvImage.Initialize("imvImage")
imvImage.Gravity=Gravity.FILL
imvImage.Tag=i
imvImage.Bitmap=bmpImage
scvImages.Panel.AddView(imvImage,lfmImage,i*(imgHeight+imgSpace),imgWidth,imgHeight)​
Next
scvImages.Panel.Height=(nbrImage+1)*(imgHeight+imgSpace)
When I Log the filenames they are correct but without double quotes (ImageList.Get(I)). When I add the quotes I get an error for the bmpImage.....line.
Is there a way of passing non-parameterized filenames to an imageview? PhilMac.
 

eurojam

Well-Known Member
Licensed User
Longtime User
If your ImageList contains Strings, there will be no need to quote ImageList.get(i).
If you need a doublequote, you can define it like this:
B4X:
Dim dquote  As String = Chr(34)
 
Upvote 0

wonder

Expert
Licensed User
Longtime User
Try this, it might work:
B4X:
ImageList.Sort(True) 'There no reason to sort the list 75 times... :)

For i = 0 To 74
    Dim imvImage As ImageView
    Dim bmpImage As Bitmap
    Dim ImageName As String

    ImageName = ImageList.Get(i) & ".jpg" 'This line was added
    bmpImage.Initialize(File.DirAssets, ImageName)

    imvImage.Initialize("imvImage")
    imvImage.Gravity = Gravity.FILL
    imvImage.Tag = i
    imvImage.Bitmap = bmpImage

    scvImages.Panel.AddView(imvImage, lfmImage, i * (imgHeight + imgSpace), imgWidth, imgHeight)
Next
scvImages.Panel.Height = (nbrImage + 1) * (imgHeight + imgSpace)


By the way, shouldn't you be using an array of ImageViews? This code makes more sense to me:
B4X:
ImageList.Sort(True)          'There no reason to sort the list 75 times... :)
Dim imvImage(75) As ImageView 'imvImage is now an array of size 75

For i = 0 To (imvImage.Lenght - 1)
    Dim bmpImage As Bitmap
    Dim ImageName As String

    ImageName = ImageList.Get(i) & ".jpg" 'This line was added
    bmpImage.Initialize(File.DirAssets, ImageName)

    imvImage(i).Initialize("imvImage")
    imvImage(i).Gravity = Gravity.FILL
    imvImage(i).Tag = i
    imvImage(i).Bitmap = bmpImage

    scvImages.Panel.AddView(imvImage(i), lfmImage, i * (imgHeight + imgSpace), imgWidth, imgHeight)
Next
scvImages.Panel.Height = (nbrImage + 1) * (imgHeight + imgSpace)
 
Last edited:
Upvote 0

PhilMac

Member
Licensed User
Longtime User
Try this, it might work:
B4X:
ImageList.Sort(True) 'There no reason to sort the list 75 times... :)

For i = 0 To 74
    Dim imvImage As ImageView
    Dim bmpImage As Bitmap
    Dim ImageName As String

    ImageName = ImageList.Get(i) & ".jpg" 'This line was added
    bmpImage.Initialize(File.DirAssets, ImageName)

    imvImage.Initialize("imvImage")
    imvImage.Gravity = Gravity.FILL
    imvImage.Tag = i
    imvImage.Bitmap = bmpImage

    scvImages.Panel.AddView(imvImage, lfmImage, i * (imgHeight + imgSpace), imgWidth, imgHeight)
Next
scvImages.Panel.Height = (nbrImage + 1) * (imgHeight + imgSpace)


By the way, shouldn't you be using an array of ImageViews? This code makes more sense to me:
B4X:
ImageList.Sort(True)          'There no reason to sort the list 75 times... :)
Dim imvImage(75) As ImageView 'imvImage is now an array of size 75

For i = 0 To (imvImage.Lenght - 1)
    Dim bmpImage As Bitmap
    Dim ImageName As String

    ImageName = ImageList.Get(i) & ".jpg" 'This line was added
    bmpImage.Initialize(File.DirAssets, ImageName)

    imvImage(i).Initialize("imvImage")
    imvImage(i).Gravity = Gravity.FILL
    imvImage(i).Tag = i
    imvImage(i).Bitmap = bmpImage

    scvImages.Panel.AddView(imvImage(i), lfmImage, i * (imgHeight + imgSpace), imgWidth, imgHeight)
Next
scvImages.Panel.Height = (nbrImage + 1) * (imgHeight + imgSpace)

THANK YOU, I WILL TRY THIS! GRATEFUL.
 
Upvote 0

PhilMac

Member
Licensed User
Longtime User
So far, still a problem trying to turn the ImageList.Get(i) into a string variable for the bmp.initialization. When reading from the DirAssets folder, the extension is included. For some reason it is not recognizing the filename as a string and/or an acceptable filename in the DirAssets folder. I am planning on moving all the files to a Picture or Image folder. I don't know if this will help, but my plan was to do so anyways. Thanks.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Can you post a small project showing your problem.
What is exactly the content of ImageList ?
Does it already have ".jpg" added or not ?
If the original name already has ".jpg" added and you add it once more the file will not be found !

In the attached program a similar code works !!!
There are different tests inside the project.
 

Attachments

  • ImageScrollView1.zip
    187.3 KB · Views: 179
Last edited:
Upvote 0

PhilMac

Member
Licensed User
Longtime User
Can you post a small project showing your problem.
What is exactly the content of ImageList ?
Does it already have ".jpg" added or not ?
If the original name already has ".jpg" added and you add it once more the file will not be found !

In the attached program a similar code works !!!
There different tests inside the project.

Thank you, Klaus. I do not get the conflict errors between the Bitmaps list type and the bitmap drawable during initialization of each bitmap. And yes, my list gets all the filenames from (the Images folder on SD now), and they all contain the extension ".jpg".

However, for now only the UP and DOWN buttons show, and are active. No images are displayed. I will keep working on this. If you think you have an idea as to why my images are not showing, it would be very much appreciated. PhilMac.
 
Upvote 0

PhilMac

Member
Licensed User
Longtime User
Thank you, Klaus. I do not get the conflict errors between the Bitmaps list type and the bitmap drawable during initialization of each bitmap. And yes, my list gets all the filenames from (the Images folder on SD now), and they all contain the extension ".jpg".

However, for now only the UP and DOWN buttons show, and are active. No images are displayed. I will keep working on this. If you think you have an idea as to why my images are not showing, it would be very much appreciated. PhilMac.

Klaus. I'm going to try your code with less than 50 pictures in the Images folder. I think this is the only problem as I see your loop exists if the size of the list is > 50. Thanks!
 
Upvote 0

PhilMac

Member
Licensed User
Longtime User
Klaus. I'm going to try your code with less than 50 pictures in the Images folder. I think this is the only problem as I see your loop exists if the size of the list is > 50. Thanks!

Turns out that the only remaining problem is making the imagesFolder be in my path instead of yours. No problem. Thank you. PhilMac.
 
Upvote 0
Top