Пытаюсь сохранить картинку, ничего не выходит. Использую два метода для сохранения и загрузки
private String saveToInternalStorage(Bitmap bitmapImage) throws IOException {
ContextWrapper cw = new ContextWrapper(getApplicationContext());
// путь /data/data/yourapp/app_data/imageDir
File directory = cw.getDir("imageDir", Context.MODE_PRIVATE);
// Создаем imageDir
File mypath=new File(directory,"user.png");
FileOutputStream fos = null;
try {
fos = new FileOutputStream(mypath);
// Используем метод сжатия BitMap объекта для записи в OutputStream
bitmapImage.compress(Bitmap.CompressFormat.PNG, 100, fos);
} catch (Exception e) {
e.printStackTrace();
} finally {
fos.close();
}
return directory.getAbsolutePath();
}
private void loadImageFromStorage(String path)
{
try {
Toast.makeText(this, "Загружено", Toast.LENGTH_LONG).show();
File f=new File(path, "user.png");
Bitmap b = BitmapFactory.decodeStream(new FileInputStream(f));
channelLogo.setImageBitmap(b);
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
}
Здесь сохраняю картинку посредством нажатия на кнопку меню
case R.id.save:
Bitmap icon = BitmapFactory.decodeResource(getApplicationContext().getResources(),
R.drawable.user);
try {
saveToInternalStorage(icon);
Toast.makeText(this, "Сохранено", Toast.LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
}
return true;
Здесь загружаю. Метод расположил в методе OnCreate
loadImageFromStorage("/data/data/yourapp/app_data/imageDir");