Skip to content

Commit

Permalink
Added support for base64-encoded images
Browse files Browse the repository at this point in the history
Added support for opening images directly as a base64-encoded string. This already worked in iOS, but threw an 'invalid URL'-error on Android.
  • Loading branch information
EggMeister committed Feb 13, 2016
1 parent 3e49ea4 commit 8ea42ba
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 8ea42ba

Please sign in to comment.