How to get the file name of an image

mhc

Member
Licensed User
Longtime User
Hey,

in an app I use an image control. I set the correspondending image during design time. Everything works fine.
Now I want to know the file name during run time. How can I get this - like imgControl.Image.FileName ?

With imgControl.Name I get the name of the control itself - but not the related filename.

Please :sign0085:

Thx
mhc
 

Cableguy

Expert
Licensed User
Longtime User
I don't understand your problem....images added at designtime are KOWN files...Why not just add a variable to hold the image filename?

If you can explain a bit more of why you need to "retrieve" the filename of a designtime set image controll filename....then maybe we can find a workaround..
 

Doctor_E

New Member
Hi there, new to forum.
I wrote this very simple code which demonstrates how to get in real-time the filenames of specific file type group (such as documents or images) directly from a specific folder which contains mixed files.

You may find it useful ;)

PS: If it is off-topic please move to correct sub-forum. Thanx in advance
 

Attachments

  • ReadFileName.zip
    2 KB · Views: 384
Last edited:

mhc

Member
Licensed User
Longtime User
Hi,

thx for your help.

Cableguy:
The idea is to select (click) one of serveral images. That triggers an event which creates another control (i.e. AddImageButton). There is no problem to assign the Sender.Image to the ImageButton.Image.
Please see the attached file to understand what I try to explain.
Now I want to save the screen in an ini-file when the app will be closed.
I thought it should be possible to get the properties of the different controls with GetControls("Form1"). Such like name, top, left, ...
And the file name of the involved image.

I know it is possible to keep a list collecting all this properties when triggering an event. But in my opinion it should be usefull and more efficient to prevent all this effort. Think about reindex when we delete one of these controls - or only change the position!

Maybe there is a more uncomplicated solution.

bye
mhc
 

agraham

Expert
Licensed User
Longtime User
Technically it is not possible to get the image filename from an Image control. An Image control is not associated with a file at all, it contains a Bitmap object that contains the image that the Image control displays.

The Bitmap object does not necessarily contain an image sourced from a file. It can be a new Bitmap from ImageLib, ImageLibEx or GDI+Desktop that has been created and drawn entirely by the application.

I am afraid there is no alternative to tracking the filenames yourself.
 

efc_dev

Member
Licensed User
Longtime User
I found this thread and today I have the same Problem.
I want to implement a Skin functionality to my Software.
So the only way to realise this is during runtime.

In my Project I've got many imagebuttons but only 20 different Pictures.
Is there a way to get a logfile from the compilation where I'll find something like this

form1.imagebutton1.Image = image1.png
..
form40.imagebutton203.Image= image2.png

a.s.o.

So I can prepare a list for replace the Images.
 
Last edited:

mjcoon

Well-Known Member
Licensed User
I found this thread and today I have the same Problem.
I want to implement a Skin functionality to my Software.
So the only way to realise this is during runtime.

In my Project I've got many imagebuttons but only 20 different Pictures.
Is there a way to get a logfile from the compilation where I'll find something like this

form1.imagebutton1.Image = image1.png
..
form40.imagebutton203.Image= image2.png

a.s.o.

So I can prepare a list for replace the Images.

Are you by any chance asking about Android s/w? This the Windows Mobile forum (See header: Home Forums > Other Products > Basic4ppc (Windows Mobile) > Questions (Windows Mobile) ) so not the best place for answers...

Mike.
 

efc_dev

Member
Licensed User
Longtime User
Are you by any chance asking about Android s/w? This the Windows Mobile forum (See header: Home Forums > Other Products > Basic4ppc (Windows Mobile) > Questions (Windows Mobile) ) so not the best place for answers...

Mike.

My Project is based on Windows mobile not android and I want to implement such a feature.
So I think the only way is to parse *.bas files and generate such a list by my own

After that I can provide this list with my application and replace all the pictures step by step.

Have a look at this

You need an arraylist alFiles and a table tblFiles.

B4X:
Sub Button1_Click
    alFiles.Clear
    ' add the main project file
    mainName="Main"
    alFiles.Add("project.sbp")
    tblFiles.Clear
    ' start scanning
    FileSearch (alFiles, AppPath, "*.bas")
    If tblFiles.ColCount<=0 Then
        tblFiles.AddCol(cString, "Name", 50, False)
        tblFiles.AddCol(cString, "FileName", 50, False)
    End If
    searchfor="addimagebutton"
    For i=0 To alFiles.Count-1
        myFileName=alFiles.Item(i)
        ' grab alle ImageButtons und füge diese der Tabelle hinzu
        FileOpen(c1, myFileName, cRead, , cASCII)
        cancel=False
        ' erste Zeile
        r = FileRead (c1)
      
          Do Until r = EOF OR cancel=True
        ' Check the line
        If r="@EndOfDesignText@" Then
            ' Found end of Designer
            cancel=True  
        Else
            ' check for ImageButton
            myfound=StrIndexOf(r, searchfor,0)
            ' yes found
            If myfound>-1 Then
                ' split it
                mySplit()=StrSplit(r, ",")
                ' grab name und image
                ' main project file?
                If  SubString(FileName(myFileName),StrLength(FileName(myFileName))-4,4)=".sbp" Then
                    myname=mainName&"."&mySplit(1)
                Else
                    ' just a bas file
                    myname=SubString(FileName(myFileName),0,StrLength(FileName(myFileName))-4)&"."&mySplit(1)
                End If
                myimage=SubString(mySplit(14),1,StrLength(mySplit(14))-2)
                ' add to table
                tblFiles.AddRow(myname,myimage)
            End If
        End If
        r = FileRead (c1)
          Loop
  
        FileClose(c1)
    Next
    ' finally save it, provide this list with your application
    ' you can use it as a reference table
    tblFiles.SaveXML(AppPath&"\imagebuttons.xml")
    tblFiles.SaveCSV(AppPath&"\imagebuttons.csv",";",True)
  
End Sub
 
Last edited:
Top