LoadBitmap Error

Bill Norris

Active Member
Licensed User
Longtime User
I have placed all of jpg files in dir.defaultexternal. When I try to use the following:

B4X:
imageview.Bitmap=LoadBitmap(File.DirDefaultExternal,"imagefile.jpg")

I get "error loading bitmap". I find that I have first copy the file to File.DirAssets then use
B4X:
imageview.Bitmap=LoadBitmap(File.DirAssets, "imagefile.jpg")

to get this to work. Not a problem, just wondering why I can't load directly from DirDefaultExternal
 

margret

Well-Known Member
Licensed User
Longtime User
You should be able to. What does the permission say for it. If you put this in your code, see what it returns:

B4X:
Msgbox(File.ExternalReadable, File.ExternalWritable)

You may have to put them in DirRootExternal. It may also be that the files are not being copied to the DirDefaultExternal folder. You should not be able to copy from your code to the DirAssets folder, something sounds wrong??
 
Last edited:
Upvote 0

Bill Norris

Active Member
Licensed User
Longtime User
RE:

Thanks for the quick reply, Margaret.
I get True in the title and True in the message. I'm afraid I mis-stated something in original post. I said I had to copy the files to DirAssets to make it work. That was a quick assumption on my part, based on the fact that if I add the image file I am trying to load into Files, I can then call it from DirAssets and it loads properly. As I read more, I read that it is not possible to copy to DirAssets. I am simply trying to avoid adding all (200) of my image files to the Files folder so the APK is no huge. Plus, I want to be able to add more images over time without generating a new APK.
 
Upvote 0

margret

Well-Known Member
Licensed User
Longtime User
You could use code like this in your app:

B4X:
If File.ExternalWritable Then
   File.MakeDir(File.DirRootExternal, "myappname/data/images")
   myimagepath = File.DirRootExternal & "/myappname/data/images/"
Else
   Msgbox("SDCard is not Writable or is not Installed", "NOTICE")
End If

You can also check on first run to see if they are there and if not, FTP them from a server of your choice.
 
Upvote 0

Bill Norris

Active Member
Licensed User
Longtime User
RE:

The image files are indeed in defaultexternal, as I can see them in file manager. It is curious to me that when we use a database, we have to copy it to defaultexternal in order to open it. Why then would I have a problem loading an image file from the same location.
 
Upvote 0

margret

Well-Known Member
Licensed User
Longtime User
The File.DirDefaultExternal most times returns a folder from the SDCard under the app name like:

/mnt/sdcard/Android/data/appname/files

There may be some system protection to this folder because it is attached to the application. This is why I suggested to create the folder in the DirRootExternal as it should be WorldReadable permissions. You might try it and see if all works ok.
 
Last edited:
Upvote 0

Bill Norris

Active Member
Licensed User
Longtime User
RE:

Upon further investigation, it appears as though the problem is not the file location but the files themselves. I used httputils to download the image files from our web server. The download goes successfully, and all of the files appear in the proper folder on the device. However, there appears to be a problem with the files. If I try to view one of them using Gallery, nothing happens. Also, the icon that appears by the file name in file manager, which is actually a mini-image of the file, is not the image at all -- some generic-looking icon thing. I am going to have to troubleshoot what is happening to the files during the download process. Not looking forward to that!
 
Upvote 0

fabio.guerrazzi

Member
Licensed User
Longtime User
Another question: is there a way to LoadBitmap from files preloaded into layout at design time? is it a specific enumerable Filre.Dirxxxx? thanks
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…