为什么在存储中保存图像是黑色的?

时间:2017-08-23 14:11:33

标签: android android-bitmap

我使用此代码将位图设置为imageView并获取图像格式imageView并将其保存在存储中,但保存时,图像为黑色!请帮忙解决这个问题!

Bitmap bitmap = ink.getBitmap();
          img_signature.setImageBitmap(bitmap);
          ByteArrayOutputStream stream = new ByteArrayOutputStream();
          bitmap.compress(Bitmap.CompressFormat.JPEG, 50, stream);
          byte[] byteArray = stream.toByteArray();
          encodedString = Base64.encodeToString(byteArray, 0);
          createDirectoryAndSaveFile(bitmap,"signature.jpg");

以及保存图片的方法:

private void createDirectoryAndSaveFile(Bitmap imageToSave, String fileName) {

File direct = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/delivery/");

if (!direct.exists()) {
  direct.mkdirs();
}

File file = new File(direct, fileName);
if (file.exists())
  file.delete();
try {
  FileOutputStream out = new FileOutputStream(file);
  imageToSave.compress(Bitmap.CompressFormat.JPEG, 100, out);
  out.flush();
  out.close();

} catch (Exception e) {
  e.printStackTrace();
}

}

0 个答案:

没有答案