Reputation: 55
I'm trying to make the app on installation have its own folder containing its own images which I would have added in the code, the images would probably be in the drawable, but I don't know how I can make selected images from drawable be in a folder of the application.
What I have tried so far:
*I have tried creating the folder but it's empty on installation and I added images to it normally but I can't get images from the drawable to the folder.
*Can I get a way to get images from the drawable into that folder or is there another way to create a folder and it should contain images that I would have selected via code.
Upvotes: 0
Views: 38
Reputation: 4289
First, we need to create a Bitmap
of the resource present in the drawable
folder like,
BitmapFactory.Options options = new BitmapFactory.Options() ;
options.inMutable = true ;
Bitmap image = BitmapFactory.decodeResource( getResources() , R.drawable.photo , options ) ;
Now, add the WRITE_EXTERNAL_STORAGE
permission to the Android Manifest,
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
You need to request this permission from the user too. Once the permission is granted, simply save the Bitmap
to a file,
FileOutputStream fileOutputStream = new FileOutputStream( imageFile ) ;
image.compress( Bitmap.CompressFormat.JPEG , 100 , fileOutputStream ) ;
Upvotes: 1