Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8366855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:01:04+00:00 2026-06-09T13:01:04+00:00

I want to decode an image from webservice which is in base64 to the

  • 0

I want to decode an image from webservice which is in base64 to the bitmap and use it in my android app.
This is my method:

public Bitmap getCaptcha() throws IOException
    { 

        List<NameValuePair> params = new ArrayList<NameValuePair>();
        String json = jsonParser.getCaptcha(captchaURL, params);
        Log.i("", json);

         byte [] encodeByte=Base64.decode(json.getBytes(),Base64.DEFAULT);
         Bitmap bitmap=BitmapFactory.decodeByteArray(encodeByte, 0, encodeByte.length);
         return bitmap;

    }

If I decode the string which I get from getCaptcha method with my php script – it displays correctly. But when I do this in my application, I get an

 FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.assignmentexpert/com.assignmentexpert.RegisterActivity}: java.lang.IllegalArgumentException: bad base-64
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:123)
    at android.app.ActivityThread.main(ActivityThread.java:3687)
   at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
    at dalvik.system.NativeStart.main(Native Method)
   Caused by: java.lang.IllegalArgumentException: bad base-64
    at android.util.Base64.decode(Base64.java:161)
    at android.util.Base64.decode(Base64.java:136)
    at com.library.UserFunctions.getCaptcha(UserFunctions.java:97)
    at com.assignmentexpert.RegisterActivity.onCreate(RegisterActivity.java:66)
   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
    ... 11 more

What’s is reason of it?

I add base64 code that I get:

/9j/4AAQSkZJRgABAQAAAQABAAD//gA7Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1c2luZyBJSkcgSlBFRyB2NjIpLCBxdWFsaXR5ID0gMTUK/9sAQwA1JSgvKCE1LysvPDk1P1CFV1BJSVCjdXthhcGqy8i+qrq31fD//9Xi/+a3uv///////////87//////////////9sAQwE5PDxQRlCdV1ed/9y63P///////////////////////////////////////////////////////////////////8AAEQgAKAB4AwEiAAIRAQMRAf/EAB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKC//EALUQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1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EYIGKKKAIHs4X527T7UwafEDyWNFFFwLMcaRLtQYFKyhhhgCPQ0UUAMFvEGyI1z9KkwKKKACiiigD/2Q==n

Problem is that when I copy the code from the browser and hardcode it to my program – everything works fine. But when I get the base64 data via my android program and try to hardcode the base64 – I get an exception. Code, which is in browser and what I get via Android looks the same. But, practically, it doesn’t because of different result)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T13:01:06+00:00Added an answer on June 9, 2026 at 1:01 pm

    It looks like the padding of your Base64 code is not good (wrong number of trailing = signs at the end of your code). For example, the base64 code corresponding to Hello is SGVsbG8=, and the last = is just there to make the size of the base64 data chunck compliant with the Base64 RFC. So SGVsbG8== and SGVsbG8 are both incorrect as the length of the chunck
    is not according to the base64 spec, even though they both mean Hello if we stick to relevant characters (the “Base 64 Alphabet”).

    Some implementations are quite permissive about that. They just assume that a base64 chunck of an incorrect length needs padding with one or two “=”. Some other, including Android, are not permissive, so the kind of discrepancy you are facing between the behaviours of your PHP and Android programs.

    This is only an assumption, as I cannot see the base64 data you are trying to decode. To check that, you can use this online base64 decoder, which will tell you whether the padding is ok.

    Anyhow it would be easier with a sample of your base64 code. Would you add that to your post? I’ll update my answer accordingly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to encode and decode Bitmap object in string base64 . I use
I want to decode a base64 encoded image received over email on Google App
I want to load image from web, then decode it by the BitmapFactory.decode() method.
I want get the image from an xml file which is encoded using base64.
I want to decode an image from the SD card with BitmapFactory.decodeFile(path, options). I
I want to send an image from android and save it trought a php
I want to upload a image(UIImage) from ios app to django website.(where has forms
i Want to fetch this data using json decode. Please Help.. So far i
I trying to resize one image from InputStream, so I use the code in
I'm using an Uri returned from image gallery to create a Bitmap. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.