Issue
Hello I want to get the drawable image path in android and then I want to create a file ? can anybody help me there ?
Solution
So, you want how to save image to sdcard from drawable resource. right?
At first get bitmap from your drawable resource and then save bitmap as image in your required location
Bitmap bitmap = BitmapFactory.decodeResource( getResources(), R.drawable.my_image);
The path to SD Card can be retrieved using:
String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
Then save to sdcard
File file = new File(extStorageDirectory, "myimagefile.png");
FileOutputStream outStream = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, outStream);
outStream.flush();
outStream.close();
Don't forget to add android.permission.WRITE_EXTERNAL_STORAGE permission in your manifest file.
Answered By - bhumik
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.