How to get the file name of an image

Discussion in 'Questions (Windows Mobile)' started by mhc, Jan 31, 2009.

  1. mhc

    mhc Member Licensed 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
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    That is not possible.
    You can set the Image property from your code and store the file name in a variable:
    Code:
    imageFile = "image.jpg"
    Image1.Image = imageFile
     
  3. mhc

    mhc Member Licensed User

    Hello Erel,

    thank you for your very quick reply.
    I feared that this will not be possible.:(
    So I have to find an other workaround.

    mhc
     
  4. Cableguy

    Cableguy Expert Licensed 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..
     
  5. Doctor_E

    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
     

    Attached Files:

    Last edited: Feb 2, 2009
  6. mhc

    mhc Member Licensed 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
     
  7. agraham

    agraham Expert Licensed 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.
     
  8. efc_dev

    efc_dev 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.
     
    Last edited: Jan 9, 2014
  9. mjcoon

    mjcoon Well-Known Member Licensed 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.
     
  10. efc_dev

    efc_dev Member Licensed User

    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.

    Code:
    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"50False)
            tblFiles.AddCol(cString, 
    "FileName"50False)
        
    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: Jan 13, 2014
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice