B4J Question For each list

dibb3386

Member
Licensed User
Longtime User
HI, i really need help with this (i know ive done similar on android at some point) but long story short heart meds, cloudy head. Dont know my ass from my elbow with them. Some days fine other days meh.

So i am trying to set an image from a list (and repeat for each item in the list) to an imageview and save the panel its on as an image. It works fine for a single image so i know am on the right track with that, but cant figure out to load the list and repeat what i can with a single image for the whole list.

Am not looking for hints at this time (happy to pay for time, must have paypal) because ill spend the next 3 days or more editing images when the idea of my little program is to do it in bulk. (So get paid because i will be once this works and am hours per day free)

Oh also ass elbow thing, i know my H for horizontal and V for vertical are the wrong way round somewhere...fix that for bonus? if not its fine.
 

Attachments

  • CIE18102020-1.zip
    6.2 KB · Views: 161

mangojack

Well-Known Member
Licensed User
Longtime User
There was no images included in your uploaded project. (and I am short time to replace them and give it a spin ... maybe later)

I am guessing this is the problem area.
B4X:
If OSelection = "H" Then
        Dim i As Int
        list1.Initialize   '@ Remove
        For i = 0 To list1-1    
            CanvasHImg.SetImage(fx.LoadImage(CanvasImg,BulkImageLV.SelectedItem))
            SavePaneToImage(PreviewHPane, CanvasImg)
        Next
    Else if OSelection = "V" Then
        Dim i As Int
        list1.Initialize    '@ Remove
        For i = 0 To list1-1
        CanvasVImg.SetImage(fx.LoadImage(CanvasImg,BulkImageLV.SelectedItem))
        SavePaneToImage(PreviewVPane, CanvasImg)
    Next
End If

List1 is declared globally and referenced throughout the project.
Why would you attempt to loop thru a freshly initialized (empty) list. ?

As a side note ... I noticed allot of calls to set views.visible and also enable/disable.
In my opinion, If you are hiding a view (.Visible = False) I don't see the need to toggle the Enabled property.... might be wrong
This would reduce your code a bit , and also possible headache.
 
Upvote 0

dibb3386

Member
Licensed User
Longtime User
Yeah file size was to big to include images. Thanks for your help ill review now.

Edit: Force of habbit (visable=false/enabled=false) after having issues on b4a a while back of panels not disabling all views.
 
Upvote 0

dibb3386

Member
Licensed User
Longtime User
So after taking out the unneeded list1.initialize , am getting this error that i dont understand.

java.lang.NumberFormatException: For input string: "(ArrayList) [[IMAG0072.jpg, IMAG0293.jpg, IMAG0318.jpg, IMAG0319.jpg, mr-bean-21.jpg]]"

Its loading the images to the list and is in an array but as far as i can understand it not working because its expecting number format? (or something to do with the floating decimal in the . jpg?)

Edit:Getting somewhere as before it was same error only ArrayList[] empty.
 
Last edited:
Upvote 0

stevel05

Expert
Licensed User
Longtime User
It'll be these lines:
B4X:
For i = 0 To list1-1

Presumably you mean
B4X:
For i = 0 To list1.Size-1
 
Upvote 0

dibb3386

Member
Licensed User
Longtime User
Thank you stevel05, next problem is ( i think the final problem) am getting the error : java.io.FileNotFoundException: null (The system cannot find the file specified)
which is obviously its not finding the .jpg file. Something to do with the CanvasImg variable i think, as it again works with single images but its not putting the image in the CanvasImg placeholder to then SavepaneToImge sub.

B4X:
If OSelection = "H" Then
        Dim i As Int
        
        For i = 0 To list1.Size-1
            CanvasHImg.SetImage(fx.LoadImage(CanvasImg,BulkImageLV.SelectedItem))
            SavePaneToImage(PreviewHPane, CanvasImg)
        Next
    Else if OSelection = "V" Then
        Dim i As Int
        
        For i = 0 To list1.Size-1
            CanvasVImg.SetImage(fx.LoadImage(CanvasImg,BulkImageLV.SelectedItem))
            SavePaneToImage(PreviewVPane, CanvasImg)
        Next
    End If
 
Upvote 0

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
hi! what i see in the code is that sometimes you use:

B4X:
File.GetName(CanvasImg)
'and others:
fx.LoadImage(CanvasImg... 'without the file.getparent,.

so it is possible taht you are not selecting the file you are looking for correctly.

this line must likely is throwing something like: C:\temp\image.jpg\image.jpg
B4X:
CanvasHImg.SetImage(fx.LoadImage(CanvasImg,BulkImageLV.SelectedItem))

i think its easy to debug, dont relay to much on logs, you can use breakpoints to stop executing code and see what the variables values are holding
 
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
I have run your above example, but cannot spend any more time on it. I have attached another with a few comments.

I am still unsure what you are trying to achieve ... but a few things I noticed (and made changes)
B4X:
Sub SelectBulkImageBtn_Click
Dim Folder As String = DirCh.Show(MainForm)


but then in the following sub , you use CanvasImg ... which is the string storing the path for a Select Single Image option.
B4X:
Sub RunBulkBtn_Click
    For i = 0 To list1.Size-1
        CanvasHImg.SetImage(fx.LoadImage(CanvasImg, BulkImageLV.SelectedItem))
        SavePaneToImage(PreviewHPane, CanvasImg)
    Next

I have created a global var ChoosenBulkImagesPath (and used that in the RunBulkBtn event)



Also ... If you are processing a single BulkImageLV.SelectedItem ... why are you iterating thru the contents of List1 ?

If you are processing bulk images would it not be something like... (totally untested suggestive code only)
B4X:
For i = 0 To list1.Size-1                   
    CanvasVImg.SetImage(fx.LoadImage(ChoosenBulkImagesPath,BulkImageLV.Items.Get(i)))
    '...............................


Any way , we are not getting any Errors , but I notice the Output Image is the Canvas image? (Should be the choosen image ??)

Hopefully this might help a bit ... or not , Cheers

PS: Hint .. maybe for variables holding FileChooser paths , use names like SingleImagePath .. BulkImagePath etc.
A name like CanvasImg to me relates to the Image on a Canvas .... (which it ends up being , but you know what I mean)
 

Attachments

  • CIE Example.zip
    96.1 KB · Views: 146
Last edited:
Upvote 0

dibb3386

Member
Licensed User
Longtime User
I have run your above example, but cannot spend any more time on it. I have attached another with a few comments.

I am still unsure what you are trying to achieve ... but a few things I noticed (and made changes)
B4X:
Sub SelectBulkImageBtn_Click
Dim Folder As String = DirCh.Show(MainForm)


but then in the following sub , you use CanvasImg ... which is the string storing the path for a Select Single Image option.
B4X:
Sub RunBulkBtn_Click
    For i = 0 To list1.Size-1
        CanvasHImg.SetImage(fx.LoadImage(CanvasImg, BulkImageLV.SelectedItem))
        SavePaneToImage(PreviewHPane, CanvasImg)
    Next

I have created a global var ChoosenBulkImagesPath (and used that in the RunBulkBtn event)



Also ... If you are processing a single BulkImageLV.SelectedItem ... why are you iterating thru the contents of List1 ?

If you are processing bulk images would it not be something like... (totally untested suggestive code only)
B4X:
For i = 0 To list1.Size-1                 
    CanvasVImg.SetImage(fx.LoadImage(ChoosenBulkImagesPath,BulkImageLV.Items.Get(i)))
    '...............................


Any way , we are not getting any Errors , but I notice the Output Image is the Canvas image? (Should be the choosen image ??)

Hopefully this might help a bit ... or not , Cheers

PS: Hint .. maybe for variables holding FileChooser paths , use names like SingleImagePath .. BulkImagePath etc.
A name like CanvasImg to me relates to the Image on a Canvas .... (which it ends up being , but you know what I mean)

Just a quick update, had my kids and one sneezed so am sick.

To clear up what am trying to do:- Make a new image by attaching to an image to a background. (Am setting this up for actual framed canvas thats sells on ebay. Hence the confusion about my variables) So i want to do this in bulk so i select the background i want to use then use a list to read a folder of all images and attach each image to an imageview on top of the background image. Then save the pane to a new image to a new folder (see image below for example).


Gameboy 1-1 b4x.jpg
 
Upvote 0
Top