I need pick an image from Drawable directory. My code is :
private void CreateViewForIndex(View rootView, int index) {
// Instantiate GPUImageView object
ImageView mGPUImageView = (ImageView)rootView.findViewById(R.id.image);
// Set an image from file inside GPUImageView object
File imageFile = new File("/MainActivity/res/drawable-hdpi/russia.jpeg");
mImageView.setImage(imageFile);
// Apply filter
mImageView.setFilter(returnFilterForIndex(index));
}
Where rootView is the View. I need to create a new File
object from an image in the following directory: /MainActivity/res/drawable-hdpi/russia.jpeg
. The problem is that I am unable to get the right directory for the previous image file so the jpeg is never displayed.
You can use following code to create file from drawable resource as-is without any additional encoding-decoding involved in the process. In this code file is saved into application private cache, but this can be easily modified to accommodate saving to any file.
You can use above method like this:
When you are no longer using created cache file it would be good to delete it in order to minimize your app storage use with
or you can clean all cached files on app exit with
However, if you cache only small number of files and/or those files do not occupy too much memory, you can safely skip that part.