如何将图像转换为base64字符串 [英] how to convert an image into base64 string

查看:86
本文介绍了如何将图像转换为base64字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将图像转换为 base 64 编码为字符串.从那里以 oma_status-icon xml 格式发送到服务器.

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....

还有其他方法可以将图片转base64字符串吗??

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

请..帮助...

我的代码是:

        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);

推荐答案

请使用此代码..

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);

请导入

import android.util.Base64;

这篇关于如何将图像转换为base64字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆