private String encodeFromImage() {
String encode = null;
if (imageView.getVisibility() == View.VISIBLE) {
Bitmap bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
encode = Base64.getEncoder().encodeToString(stream.toByteArray());
} else {
encode = android.util.Base64.encodeToString(stream.toByteArray(), android.util.Base64.DEFAULT);
}
}
return encode;
}