Image to Byte Array to String (and vice versa) in android?
<p>I'd like to convert an image into a byte array, then convert that byte array into a string. Also, I'd then like to convert that string back to a byte array, and finally back to an image in adroid . How might I go about accomplishing this? Any help will be appreciated.</p>

<p>this is to convert inputstream to string    </p>

<pre><code>private String convertInputStreamToString(InputStream in){

        try {
            byte[] b=new byte[8000];
            in.read(b);
            String base64String=Base64.encode(b);
            return base64String;

        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }

    }
</code></pre>

<p>and this to convert string to inputstream </p>

<pre><code>String imageString =Settings.getCurrentUserImage(c);// it is the encoded string 
                byte[] bytearray = Base64.decode(imageString);      
                InputStream is =new ByteArrayInputStream(bytearray);
                Drawable dUser = Drawable.createFromStream(is , "src"); 
                userImg.setImageDrawable(dUser); 
</code></pre>

<p>is this correct ?!
I have error in this line of code </p>

<pre><code>InputStream is =new ByteArrayInputStream(bytearray);
</code></pre>

<p>where the error is ..</p>

<pre><code>02-22 23:31:30.268: ERROR/AndroidRuntime(611): FATAL EXCEPTION: main
02-22 23:31:30.268: ERROR/AndroidRuntime(611): java.lang.NullPointerException
02-22 23:31:30.268: ERROR/AndroidRuntime(611):     at java.io.ByteArrayInputStream.&lt;init&gt;(ByteArrayInputStream.java:58)
02-22 23:31:30.268: ERROR/AndroidRuntime(611):     at aynoo.forms.FreindMessagesActivity.addMessage(FreindMessagesActivity.java:294)
02-22 23:31:30.268: ERROR/AndroidRuntime(611):     at aynoo.forms.FreindMessagesActivity.getMessagesFromJSON(FreindMessagesActivity.java:459)
02-22 23:31:30.268: ERROR/AndroidRuntime(611):     at aynoo.forms.FreindMessagesActivity.access$3(FreindMessagesActivity.java:433)
02-22 23:31:30.268: ERROR/AndroidRuntime(611):     at aynoo.forms.FreindMessagesActivity$3.run(FreindMessagesActivity.java:190)
02-22 23:31:30.268: ERROR/AndroidRuntime(611):     at android.os.Handler.handleCallback(Handler.java:587)
02-22 23:31:30.268: ERROR/AndroidRuntime(611):     at android.os.Handler.dispatchMessage(Handler.java:92)
02-22 23:31:30.268: ERROR/AndroidRuntime(611):     at android.os.Looper.loop(Looper.java:123)
02-22 23:31:30.268: ERROR/AndroidRuntime(611):     at android.app.ActivityThread.main(ActivityThread.java:3647)
02-22 23:31:30.268: ERROR/AndroidRuntime(611):     at java.lang.reflect.Method.invokeNative(Native Method)
02-22 23:31:30.268: ERROR/AndroidRuntime(611):     at java.lang.reflect.Method.invoke(Method.java:507)
02-22 23:31:30.268: ERROR/AndroidRuntime(611):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
02-22 23:31:30.268: ERROR/AndroidRuntime(611):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
02-22 23:31:30.268: ERROR/AndroidRuntime(611):     at dalvik.system.NativeStart.main(Native Method)
</code></pre>
