如何将图像转换成的base64串 [英] how to convert an image into base64 string

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

问题描述

我想转换形象立足64 EN code字符串。从发送给服务器 oma_status图标 XML格式。

但我正在逐渐不受支持的编码来自服务器的响应......

是那里图像转换为Base64字符串??

任何其他方式

plz..help ...

我的code是:

 位图bitmapOrg = BitmapFactory.de codeResource(getResources(),R.drawable.image);

        ByteArrayOutputStream宝=新ByteArrayOutputStream();
        bitmapOrg.com preSS(Bitmap.Com pressFormat.JPEG,100,宝);
        byte []的BA = bao.toByteArray();

         字符串BA1 = Base64.en codeBytes(BA);
 

解决方案

请使用code ..

 位图bitmapOrg = BitmapFactory.de codeResource(getResources(),R.drawable.image);
ByteArrayOutputStream宝=新ByteArrayOutputStream();
bitmapOrg.com preSS(Bitmap.Com pressFormat.JPEG,100,宝);
byte []的BA = bao.toByteArray();
字符串BA1 = Base64.en codeToString(BA,Base64.DEFAULT);
 

请输入

 进口android.util.Base64;
 

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

解决方案

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;

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

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