Pushpa.Prakruthi wrote: i need to display the Image name and load that image to file.
You meant like:
Displaying: "
myImage.png" and >>
save<< it to an 'external' file,
like on
SDCard :?:
I was not aware of a function returning the name (what is the filename without the file-ending) of a known resource (knowing only its ID), so I coded one myself:
Example-Call:Using java Syntax Highlighting
// Example-Call:
String resName = getResourceNameFromClassByID(R.drawable.class, R.drawable.icon);
// resName would be 'icon'.
Parsed in 0.031 seconds, using
GeSHi 1.0.8.4
The Source:Using the Java Reflection API this was not hard to do.
Using java Syntax Highlighting
/**
* Determines the Name of a Resource,
* by passing the <code>R.xyz.class</code> and
* the <code>resourceID</code> of the class to it.
* @param aClass : like <code>R.drawable.class</code>
* @param resourceID : like <code>R.drawable.icon</code>
* @throws IllegalArgumentException if field is not found.
* @throws NullPointerException if <code>aClass</code>-Parameter is null.
* <br><br>
* <b>Example-Call:</b><br>
* <code>String resName = getResourceNameFromClassByID(R.drawable.class, R.drawable.icon);</code><br>
* Then <code>resName</code> would be '<b>icon</b>'.*/
private String getResourceNameFromClassByID(Class<?> aClass, int resourceID)
throws IllegalArgumentException{
/* Get all Fields from the class passed. */
Field[] drawableFields = aClass.getFields();
/* Loop through all Fields. */
for(Field f : drawableFields){
try {
/* All fields within the subclasses of R
* are Integers, so we need no type-check here. */
/* Compare to the resourceID we are searching. */
if (resourceID == f.getInt(null))
return f.getName(); // Return the name.
} catch (Exception e) {
e.printStackTrace();
}
}
/* Throw Exception if nothing was found*/
throw new IllegalArgumentException();
}
Parsed in 0.037 seconds, using
GeSHi 1.0.8.4
So all you requested would be like the following:
Using java Syntax Highlighting
try {
String resName = getResourceNameFromClassByID(R.drawable.class, R.drawable.icon);
Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.icon);
bm.compress(Bitmap.CompressFormat.PNG, 100, openFileOutput(resName + ".png", MODE_WORLD_READABLE));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Parsed in 0.036 seconds, using
GeSHi 1.0.8.4
Let us know if it helped you

Regards,
plusminus