1

When I execute bitmap.getHeight(); I got a nullPointerException. This is how I try to get my bitmap:

In my json:"pic":"iVBORw0KGgoAAAANSUhEUgAAAgAAAAGACAIAAABUQk3......."

I retrieve from json the following:

byte[] decode = Base64.decode(jsonObj.getString("pic"), Base64.DEFAULT);
Log.i("size",decode.length+""); //65535
Bitmap pic = getImage(decode);

public static Bitmap getImage(byte[] image) {
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inPreferredConfig = Bitmap.Config.ARGB_8888;
    return BitmapFactory.decodeByteArray(image, 0, image.length,options);
}

But I can't display the image. Any ideas?

4
  • 1
    Exactly where is your ´bitmap´ variable, and where do you execute ´getHeight()´? Commented Sep 20, 2016 at 8:29
  • What is the stacktrace? Please always post with stacktrace. Commented Sep 20, 2016 at 8:30
  • you may try this link<br/> - stackoverflow.com/questions/11613594/… - stackoverflow.com/questions/11547327/… Commented Sep 20, 2016 at 8:32
  • My Bitmap variable is pic and whatever operation I try to do with it is giving me nullpointerexception. Thanks Arif, that link will be very useful when trying to convert bitmaps retrieving Blob from my local database, but for now is not giving me the solution to this. Commented Sep 20, 2016 at 8:43

1 Answer 1

0

The error must be inside BitmapFactory.decodeByteArray and most probably the source of the problem is unsupported image format. Check that you pass base64 encoded jpeg, png, gif or bmp.

Also if you get 65535 as decode's size - it is very suspicious. Maybe the data is trimmed in database (if you have limit of 65535 for blob size) or somewhere else.

Sign up to request clarification or add additional context in comments.

5 Comments

Thats the problem, I can't go further than 65KB to store... I need to compress previously. Thanks.
Check that you pass base64 encoded jpeg, png, gif or bmp. No. Certainly not base64 encoded. And i think that gif and bmp are not supported too.
Certainly yes, because Base64.decode is called in the code.
Mmm.. that is new for me. Never saw that done. Sorry for the confusion.
As i had problems to believe this i did a test and base64 encoded a byte array for which BitmapFactory.decodeByteArray() delivered a perfect bitmap. After encoding it failed.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.