1

I use a Base64 String to save my image and want to convert it to a Bitmap in Android. The Problem is that the Image View is black in the lower area. I also tried it with another images, but I am facing the same problem there.

My Code:

byte[] decodedString = Base64.decode(rezept.getBildtxt(), Base64.DEFAULT);
    Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
    rezeptImage.setImageBitmap(decodedByte);

Thats how it looks like:

As you can see the picture is black in the bottom area

Any Ideas ?

1
  • 1
    Are you sure, the image data is not getting clipped before it's getting base64 encoded? i.e. the data you are decoding is already corrupted? I'll suggest, if your program is reading the image, break into the code when you read the image, copy the contents and save them manually into a file. Try to open that file in some image viewer. You should also verify when you convert image data to base64 (encode), the output is valid - you can compare your base64 encoded output with some third party tool's output of encoding the image data (e.g. Notepad++) Commented Dec 3, 2018 at 21:43

1 Answer 1

2

I also use such a code to convert a Base64 String to an Bitmap. I am pretty sure your Base64 String is just wrong or to short.

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

1 Comment

Yes i found the Bug the base64 was just too short.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.