I use this code for set bitmap to imageView and get image form imageView and save it in storage but when save it, the image is black! please help to solve this problem!
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");
and method for save image :
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();
}
}