From f2ffecf2375df404c16f815bd774e16699f87b0f Mon Sep 17 00:00:00 2001 From: Matt Dupree Date: Sun, 30 Jul 2017 08:47:32 -0400 Subject: [PATCH] replace low-level bitmap handling code with glide The code that is in place currently decodes a bitmap on the main thread, which can cause application responsiveness issues. The code also doesn't appear to scale down the bitmap in cases where the bitmap is much larger than the ImageView size. These two issues are described here: https://developer.android.com/topic/performance/graphics/index.html It looks like they recommend the use of Glide to handle these problems, so I've replaced the lower-level code with Glide code. This code may not be correct. I've never used glide (I typically use Picasso). --- README.md | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 9d6c4a2..02de00c 100644 --- a/README.md +++ b/README.md @@ -114,15 +114,11 @@ public void pickImageFromGallery(View view) { // Declare a stream to read the image data from the SD card InputStream inputStream; - try { - // The content resolver provides applications access to persistent data - // Then openInputStream() opens a stream on to the content associated with a content URI. - inputStream = getContentResolver().openInputStream(imageUri); - + try { // Get a bitmap from the stream - Bitmap bitmap = BitmapFactory.decodeStream(inputStream); - - imageView.setImageBitmap(bitmap); + Glide.with(this) + .load(imageUri) + .into(imageView); } catch (FileNotFoundException e) { e.printStackTrace(); // Show a message to the user indicating that the image is unavailable