Android: Storing Image into project directory (files)?

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

Answers


You have to put the images in the res/drawable folder. Then, you can access them by 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, you better save them in the assets folder. Then, you can access them by 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 programatically 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 can't save it to your project directory. I recommend you to read the documentation about how android packages work, because it seems you don't understand.


Need Your Help

Turn SQL query into ActiveRecord Relation

sql ruby-on-rails activerecord ruby-on-rails-4 active-relation

How can I turn the following SQL query into an ActiveRecord relation so that I can expand on it with scopes?

form validation using ajax/jquery in Joomla

ajax jquery joomla joomla1.5

I want to create custom form validation in joomla using ajax or jQuery. on-blur when user input a invalid thing it should validated and show the error and all error messages should read from xml. P...

PHP Returning an object from a function

php

My problem is this (In PHP):