tags:

views:

262

answers:

1

Hello

In my application I am converting base64 string to image.For that I initially converted base 64 file to byte array and later am trying to convert to images. To convert to Images I am using the below code

    File sdImageMainDirectory = new File("/data/data/com.ayansys.Base64trial");
    FileOutputStream fileOutputStream = null;
    String nameFile="Images";
    try {

        BitmapFactory.Options options=new BitmapFactory.Options();
        options.inSampleSize = 5;
        options.inDither = true; 
        options.inPreferredConfig = Bitmap.Config.ARGB_8888;
        Bitmap myImage = BitmapFactory.decodeByteArray(imageData, 0, imageData.length);


        fileOutputStream = new FileOutputStream(
                sdImageMainDirectory.toString() +"/" + nameFile + ".jpg");


        BufferedOutputStream bos = new BufferedOutputStream(
                fileOutputStream);

        myImage.compress(CompressFormat.JPEG, quality, bos);

        bos.flush();
        bos.close();

but am getting my image as null at

Bitmap myImage = BitmapFactory.decodeByteArray(imageData, 0, imageData.length);

Please let me know your valuable suggestions.

Thanks in advance :)

+1  A: 

decodeByteArray will not convert base 64 encoding to byte array. You need to use Base64 to byte array converter first

the100rabh
Yes i am using that to convert byte array to bitmap images.But am getting null error.The Imagedata that i am passing is the byte array.
Remmyabhavan