можно использовать следующий код:
//create a file to write bitmap data
File f = new File(context.getCacheDir(), filename);
//f.createNewFile(); (No need to call as FileOutputStream will automatically create the file)
//Convert bitmap to byte array
Bitmap bitmap = your bitmap;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.PNG, 0 /*ignored for PNG*/, bos);
byte[] bitmapdata = bos.toByteArray();
//write the bytes in file
FileOutputStream fos = new FileOutputStream(f);
fos.write(bitmapdata);
fos.flush();
fos.close();
вы также можете попробовать этот метод: он не преобразует растровое изображение в массив байтов ..
private static void bitmap_to_file(Bitmap bitmap, String name) {
File filesDir = getAppContext().getFilesDir();
File imageFile = new File(filesDir, name + ".jpg");
OutputStream os;
try {
os = new FileOutputStream(imageFile);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, os);
os.flush();
os.close();
} catch (Exception e) {
Log.e(getClass().getSimpleName(), "Error writing bitmap", e);
}
}
код, чтобы сделать сделать было выложено здесь так часто. Просто Google немного. Или прочитайте двадцать страниц с тегами Android. В принципе вы сжимаете растровое изображение в поток вывода файла. – greenapps
Спасибо .. Я искал его, но кажется, что не могу его найти. – SNos
Это поможет вам http://stackoverflow.com/questions/17674634/saving-and-reading-bitmaps-images-from-internal-memory-in-android – MdFazlaRabbiOpu