Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

android - how to convert an image into base64 string

I want to convert image to base 64 encode to string. from that to send to server with oma_status-icon xml format.

but I am getting unsupported encoding from the server response....

is there any other way to convert image to base64 string??

plz..help...

my code is:

        Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),  R.drawable.image);

        ByteArrayOutputStream bao = new ByteArrayOutputStream();
        bitmapOrg.compress(Bitmap.CompressFormat.JPEG, 100, bao);
        byte [] ba = bao.toByteArray();

         String ba1=Base64.encodeBytes(ba);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Please use this code..

Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),  R.drawable.image);
ByteArrayOutputStream bao = new ByteArrayOutputStream();
bitmapOrg.compress(Bitmap.CompressFormat.JPEG, 100, bao);
byte [] ba = bao.toByteArray();
String ba1=Base64.encodeToString(ba,Base64.DEFAULT);

Please import

import android.util.Base64;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...