Android: Saving image to project directory (files)?

I want to save a Bitmap image to a project directory. How can I access the project folder or what is the address of my project folder?

+4
source share
1 answer

You must put the images in the res/drawable . Then you can access them using: R.drawable.name_of_image (for name_of_image.png or name_of_image.jpg ).

If you want to access them by their original name, it is better to save them in the assets folder. Then you can access them using the AssetManager :

 AssetManager am = getResources().getAssets(); try { InputStream is = am.open("image.png"); // use the input stream as you want } catch (IOException e) { e.printStackTrace(); } 

If you want to save a programmatically created image, you can do:

 try { FileOutputStream out = new FileOutputStream(context.getFilesDir().getAbsolutePath()+"/imagename.png"); bmp.compress(Bitmap.CompressFormat.PNG, 100, out); } catch (Exception e) { e.printStackTrace(); } 

You cannot save it in your project directory. I recommend that you read the documentation on how android packages work, because it seems like you don't understand.

+11
source

All Articles