Android Question What is File.DirAssets

Fayez Boulos

Member
Licensed User
In my trials for learning, I came across this example for Loadbitmap function. Obviously, it does not work when I run the code, and compilation error indicate file does not exist. However, What is the File.DirAssets and where is it located? is it on the phone?. Please help, and here is the part of the function
B4X:
Sub TestFancyText()
    Private  cs As CSBuilder 
    cs.Initialize.Size(18).Typeface(Typeface.MONOSPACE) 
    cs.Image(LoadBitmap(File.DirAssets, "edelweiss.jpg"), 60dip, 40dip, False).Append(" Edelweiss").Append(CRLF) 
    cs.PopAll 
    Label1.Text = cs
End Sub

by the way, the compilation error indicates
java.io.FileNotFoundException: /data/data/b4a.example/files/virtual_assets/edelweiss.jpg: open failed: ENOENT (No such file or directory)

So File.DirAssets is translated to /data/data/b4a.example/files/virtual_assets. Is that a folder that I need to create under the project root, or what?

I appreciate your help
 

Fayez Boulos

Member
Licensed User
Actually,
All what I want for now is to display a jpg file in an imageView. The question is where to put this jpg file in the source project folders and how to access it? Thanks
 
Upvote 0

Fayez Boulos

Member
Licensed User
I am still reading threads to know File.DirAssets but in vain,
I will try to ask the question differently,

  • I have a personal file MyPicture.jpg on my development PC
  • I want grammatically to load this file into an imageview
  • Where should I put that file so that LoadbitMap(File.DirAssets, "MyPicture.jpg") can find it and successfully compile at least.
    • Should I create a folder path called File.DirAssets under the project home and copy the file to it?
    • Is it a predefined path (Like that of additional libraries) where I should copy the file to?
    • Is it a virtual location on the phone?... In this case it should not fail the compilation
    • Is it a virtual path on the development PC?... In this case what is the physical path to it?
    • Is it a location under the project folders "Files OR bin OR... "?
  • Remember, The file Mypicture.jpg is a part of my source, i.e. it is not picked up from the phone (For example my logo).
Please help... I know it could be clear to you guys, but I really cannot find an answer.

If you have a project with simple ImageView where this statement is used and which successfully compiles... It will be great

Thanks again
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
What is the File.DirAssets and where is it located?
  1. Ciick on the file tab which is on the right pane of the IDE. The file tab is shown with a manilla folder symbol.
  2. Click on the button ‘Add Files’ which is just above the manilla folder
  3. A window will open up that allows you to browse and look for the location on your PC of the file called: edelweiss.jpg
  4. Click on the file and then click open to insert that file into the assets folder of your project. The file will then be shown on that pane. That is all
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Hadn't you seen the answer HERE?

If you want to use image files in the Designer you must add those in the Designer in the Files Tab.

upload_2019-2-17_12-57-12.png
 
Last edited:
Upvote 0

Fayez Boulos

Member
Licensed User
Thanks Mahares,
I Did what you said, and The code now compiles. I appreciate it.

Thanks Klaus,
I did not see your last comment about my previous thread regarding EdtItem_DocusChanged, and the jpg files... could be because the page was not refreshed on my computer !!!... sorry for that,

Regarding the images showing in the design time. Here is a screenshot showing the files in Files Tab, however, non of them show in the drop down list of the property "Image File" of the imageview... Am I missing something? I appreciate your help.

upload_2019-2-17_11-59-47.png
 
Upvote 0
Top