Я пытаюсь взять изображение, оптимизировать его как 65% JPEG и сохранить его в памяти телефона.Приведенный ниже код отлично работает для меня на моем нексусе, но возвращает исключение нулевого указателя в последней строке.
Есть идеи, что я делаю неправильно?Спасибо
// image passed in from camera
Bitmap bm = BitmapFactory.decodeFile(selectedImagePath, opts);
// create output
FileOutputStream fileOutputStream = null;
// create filename & directory
String nameFile = "ms" + String.valueOf(System.currentTimeMillis())+ ".jpg";
String directory = "/DCIM/MySeats/";
// try creating the directories if they don't already exist
File file = new File(Environment.getExternalStorageDirectory(),directory);
file.mkdirs();
// prep output
fileOutputStream = new FileOutputStream(Environment.getExternalStorageDirectory().toString()+ directory + nameFile);
optimizedImagePath = Environment.getExternalStorageDirectory().toString()+ directory + nameFile;
// write file through a buffered stream
BufferedOutputStream bos = new BufferedOutputStream(fileOutputStream);
// This line causes a null pointer exception on some phones?
// What am I missing?
bm.compress(CompressFormat.JPEG, 65, bos);