Skip to content

Commit

Permalink
Merge pull request #17 from EggMeister/patch-1
Browse files Browse the repository at this point in the history
Added support for base64-encoded images
  • Loading branch information
sarriaroman committed Feb 15, 2016
2 parents 3e49ea4 + 8ea42ba commit b0a2193
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/android/PhotoActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import uk.co.senab.photoview.PhotoViewAttacher;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Environment;
import android.util.Base64;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
Expand Down Expand Up @@ -137,11 +139,18 @@ public void onError() {
finish();
}
});
} else {
photo.setImageURI(Uri.parse(imageUrl));

hideLoadingAndUpdate();
}
} else if ( imageUrl.startsWith("data:image")){
String base64String = imageUrl.substring(imageUrl.indexOf(",")+1);
byte[] decodedString = Base64.decode(base64String, Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
photo.setImageBitmap(decodedByte);

hideLoadingAndUpdate();
} else {
photo.setImageURI(Uri.parse(imageUrl));

hideLoadingAndUpdate();
}
}

/**
Expand Down

0 comments on commit b0a2193

Please sign in to comment.