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

  • Home
  • SEARCH
  • 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 8158793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:43:54+00:00 2026-06-06T17:43:54+00:00

I have a .net ASMX webservice that I’m consuming using the ksoap2 library. In

  • 0

I have a .net ASMX webservice that I’m consuming using the ksoap2 library. In the service, I first save the user image and later retrieve it. However, once I retrieve it, the byte array is intact, but the BitmapFactory is unable to decode it and returns a null.

To convert to byte array:

Bitmap viewBitmap = Bitmap.createBitmap(imageView.getWidth(),
imageView.getHeight(), Bitmap.Config.ARGB_8888);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
viewBitmap.compress(CompressFormat.PNG, 0 /* ignored for PNG */, bos);
byte[] bitmapdata = bos.toByteArray();

The webservice accepts the bytearray in the byte[] format.

To convert the array into bitmap:

byte[] blob= info.get(Main.KEY_THUMB_BYTES).getBytes();
Bitmap bmp=BitmapFactory.decodeByteArray(blob,0,blob.length); // Return null :(
imageView.setImageBitmap(bmp);

From partial-analysis, it appears that the byte array does not change. Then why does decoding return null? Is there a better to save an image and pass it through a webservice? I didn’t analyze the whole byte array, so I’m guessing it might’ve changed a bit.

Any thoughts? Many thanks!

UPDATE:
I just tried converting the byte[] to string using:

Base64.encodeToString( bos.toByteArray(), Base64.DEFAULT);

And decode using:

byte[] blob= Base64.decode(info.get(Main.KEY_THUMB_BYTES));

Now all i get is a White picture. I’m not sure what’s wrong here. Please help.

UPDATE:
I’m storing this image inside of a database, in a column of type varchar(max). Should I be storing this byte array string inside a different sql data type? I’m not too experienced with SQL, so I used varchar because it did not convert text to unicode, which I thought might be good for thie byte array.

Thanks!

  • 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-06T17:43:55+00:00Added an answer on June 6, 2026 at 5:43 pm

    convert your byte arrays to Base64 that is a string and easy to transfer:

    public static String bitmapToBase64(Bitmap bitmap) {
            byte[] bitmapdata = bitmapToByteArray(bitmap);
            return Base64.encodeBytes(bitmapdata);
        }
    
        public static byte[] bitmapToByteArray(Bitmap bitmap) {
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            bitmap.compress(CompressFormat.PNG, 0 /* ignored for PNG */, bos);
            byte[] bitmapdata = bos.toByteArray();
            return bitmapdata;
        }
    

    and

    public static Bitmap base64ToBitmap(String strBase64) throws IOException {
        byte[] bitmapdata = Base64.decode(strBase64);
        Bitmap bitmap = BitmapFactory.decodeByteArray(bitmapdata, 0,
                bitmapdata.length);
        return bitmap;
    }
    

    also you can do it not only on image files but also on every file types:

    public static String fileToBase64(String path) throws IOException {
        byte[] bytes = fileToByteArray(path);
        return Base64.encodeBytes(bytes);
    }
    
    public static byte[] fileToByteArray(String path) throws IOException {
        File imagefile = new File(path);
        byte[] data = new byte[(int) imagefile.length()];
        FileInputStream fis = new FileInputStream(imagefile);
        fis.read(data);
        fis.close();
        return data;
    }
    
    
    public static void base64ToFile(String path, String strBase64)
            throws IOException {
        byte[] bytes = Base64.decode(strBase64);
        byteArrayTofile(path, bytes);
    }
    
    public static void byteArrayTofile(String path, byte[] bytes)
            throws IOException {
        File imagefile = new File(path);
        File dir = new File(imagefile.getParent());
        if (!dir.exists()) {
            dir.mkdirs();
        }
        FileOutputStream fos = new FileOutputStream(imagefile);
        fos.write(bytes);
        fos.close();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .NET web service (using asmx...have not upgraded to WCF yet) that
I have an ASMX webservice that returns XElement - (not an .svc WCF service)
We have an ASMX web service which we invoke from our ASP.NET application using
I have an old style .NET ASMX (SOAP/XML) webservice that is used to upload
I have an ASP.NET webservice (.asmx) with a simple method that reads something from
I have a asp.net 3.5 site with a *.asmx that serves several webservice methods.
I have created simple .NET Web Service (ASMX) that I call from my .NET
I have a asp.net asmx service and i would like to convert it to
We have a ASP.NET website project. In the past, we had been using asmx
I have .Net service that listens on single port over TCP protocol. Clients connect

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.