read and write images in structure folder - android

I'm building a travel infomation. My app has about 500 images in structure folder.
I don't know how to read/write by my application.
I usually read and write image by id through drawable. But put 500 image on drawable folder may be a wrong place.
what should I do? It would be awesome if someone had some example code.

Related

How to access an image file from assets in Flutter that has spaces in it's name?

Working on a Flutter application project that has some absurd naming conventions from the design team which prepares image assets, therefore the following question.
What's the syntax to access an image file which has spaces in it's name? For example I have an image named "United Arab Emirates.png" residing in my assets path i.e "assets/Flags/United Arab Emirates.png" When I try to access this path in Image.asset() widget I am unable to load it because the image has spaces in it's name. If I remove the space I can load it and show it in the widget. The problem here is I can not rename a huge amount of images I have in my assets directory and don't know how to write a script to rename all the assets and don't want to invest time learning how to write a script.
There must be some syntax to access these assets as I think this is a pretty generic issue that should have happened with lot of people but I don't see any questions or answer posted regarding this.
I think flutter add assets to embed , like res/draw in android, not assets folder, so the filename can not include space or other unexpected chars

Setting ImageView src from an image in Windows's drive

I have an image in my D drive (D:\...\Image.jpg) and I want to display it in my app, the thing is Im getting the image name from the database, and in my code Im doind something like:
image_view.setImageBitmap(BitmapFactory.decodeFile("D:\\Program Files\\Image_Folder\\"+item.Img_Name));
But Im getting an error saying there is no such file as (D:\Program Files...\Image.jpg), basically it's a No File Found Exception but Im sure the path is correct.
So I can't add it to drawable folder because I don't know wich image the user will select, and it would be silly to put all the images in the drawable folder to avoid this problem.
Any Ideas ?! Thank you.
You can't access images on another device like that. You need to either put all the images you need in the drawable folder, or set up a webserver on which you can get the images over a network connection.
You can get image only from device file directory, assets or drawable folders.
You can't access from your local drive it is supposed to be somewhere in your package or alternatively if only local directory is the option you can setup an ftp server through FileZilla (Server) and access your local drive through sharing.
Thanks

How to store the all jpg pictures that I've used in program

I want to implement an art game android application in Android Studio. But I'm confused about how to store the pictures? There will be 100 or more pictures of art works in game. The idea came to my mind is to minimize the sizes of pictures and adding them in drawable folder. Is there any efficient way to do that?
Thanks
First of all use TinyPng to compress your images without loosing ANY quality, I said ANY and I mean it.
and second don't put them in drawable because android will increase there sizes when you will generate signed APK, instead you should put them in raw directory which you can create in res directory, like res/raw.
Raw directory works same as drawable and any files in this directory gets resource Ids just like drawables so you can access files in it just like R.raw.yourimage.
I work on applications which includes hundreds of images and this is the best approach I have used.
Hope it helps.
If you are concerned with the space the 100 images takes up you could use a tool like photoshop or similar so compress your images to desired size (publish to web in photoshop).
Other than that I dont see why you shouldnt just save them in a drawable folder.

How to display any of 50 small images stored locally with application in a single dedicated folder

I want my program to be able to list all the 50 images that are in a local directory and access them at run time. I have tried to store them under the res folder, such as in Drawable, but have found out, according to one source, Ivan Memruk (here) that you can't refer to res folder subfolders by their folder names, because the folder names are all ignored -- you have to just use unique names for all your images and then refer to them by that name and using the whole R and resource id thing.
Also, according to that same article by Ivan, you can use subfolders under the assets folder, but then you can only access the images in them using an input stream, and (apparently) that is not of much use for accessing images.
Whoo, well all that said, does anyone have any other thoughts on an easy way to list all the images in a folder? I don't want to use the SD card by the way as my images will be shipped with the application.
Thanks in advance and thanks to the people who answered before I updated my question.
Store the images in drawables folder. But maintaining their identifiers (R.drawable) is a problem. You can get the identifiers anytime from :
getResources().getIdentifier(imageName,"drawable", context.getPackageName());
This will return R.drawable value of image.
The advantage of storing images in drawable folder is you can store resolution specific and orientation specific images.
You may use the assets folder for this purpose, remember not to name the images folder within assets as images, otherwise some extra images will come up in the image list when asked for. Instead try to give a unique name like app_images, etc.

4 MB .txt file in android application

I have a really big .txt file ( 4.2MB) that I have to access in my android application. It consists of words and their definitions in this format:
word - definition
word2 - definition2
Should I put this file in /assets folder or in res/raw? Or something third? Maybe I should put it on SD card because of its size?
And how should I get file contents in the code?
I have tried both assets and res/raw, but the file size always seems to be the problem or I am doing something wrong.
A SQLLite database could be used for this.
An example of this can be found in the latest android SDK. http://developer.android.com/resources/samples/SearchableDictionary/index.html
Putting it in raw folder would be a better idea according to me.
since putting in the SDCard would make it available to user also, and the user might screw up your database.

Categories

Resources