Tuesday, 17 June 2014

how to store bitmap in the particular file with user specified name in android

public static boolean storeImage(Bitmap imageData, String filename,
String iconStoragepath) {

File sdIconStorageDir = new File(iconStoragepath);
sdIconStorageDir.mkdirs();
try {
String filePath = sdIconStorageDir.toString() + "/" + filename;
FileOutputStream fileOutputStream = new FileOutputStream(filePath);
BufferedOutputStream bos = new BufferedOutputStream(
fileOutputStream);
imageData.compress(CompressFormat.PNG, 90, bos);
bos.flush();
bos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
return false;
} catch (IOException e) {
e.printStackTrace();
return false;
}
return true;
}

No comments:

Post a Comment