В последние несколько дней у меня возникла проблема: я пытался проверить каждую деталь, чтобы определить, что может быть причиной того, что изображение не отображается в ImageView, но мне не удалось найти ошибку. .
Что еще более сбивает с толку, так это то, что одно и то же растровое изображение устанавливается в другой фрагмент и там оно отображается правильно, но здесь оно не отображается.
Вот XML для ImageView:
И вот код:
ShapeableImageView profile_image_save_results;
profile_image_save_results = view.findViewById(R.id.profile_image_save_results);
SharedPreferences sharedPreferences = requireContext().getSharedPreferences("app_prefs", Context.MODE_PRIVATE);
String frontFaceBase64 = sharedPreferences.getString("front_face_image", null);
if (frontFaceBase64 != null) {
// Decode Base64 string to byte array
byte[] frontFaceByteArray = Base64.decode(frontFaceBase64, Base64.DEFAULT);
// Convert byte array to Bitmap
Bitmap frontFaceBitmap = BitmapFactory.decodeByteArray(frontFaceByteArray, 0, frontFaceByteArray.length);
// Set the Bitmap to ImageView
if (frontFaceBitmap != null) {
profile_image_save_results.setImageBitmap(frontFaceBitmap);
} else {
Toast.makeText(requireContext(), "Failed to decode Bitmap from byte array", Toast.LENGTH_SHORT).show();
Log.d("ImageView", "Failed to decode Bitmap from byte array");
}
} else {
Log.d("ImageView", "No image found in SharedPreferences");
}
Интересно, что всплывающее сообщение не появляется, а общее предпочтение не равно нулю. В другом фрагменте используются одни и те же общие настройки, как упоминалось ранее:
SharedPreferences sharedPreferences = requireContext().getSharedPreferences("app_prefs", Context.MODE_PRIVATE);
String frontFaceBase64 = sharedPreferences.getString("front_face_image", null);
if (frontFaceBase64 != null) {
// Decode Base64 string to byte array
byte[] frontFaceByteArray = Base64.decode(frontFaceBase64, Base64.DEFAULT);
// Convert byte array to Bitmap
Bitmap frontFaceBitmap = BitmapFactory.decodeByteArray(frontFaceByteArray, 0, frontFaceByteArray.length);
// Set the Bitmap to ImageView
if (frontFaceBitmap != null) {
profile_image.setImageBitmap(frontFaceBitmap);
} else {
Log.d("ImageView", "Failed to decode Bitmap from byte array");
}
} else {
Log.d("ImageView", "No image found in SharedPreferences");
}
Подробнее здесь: https://stackoverflow.com/questions/791 ... -imageview