在Android中的base64字符串连接code和德code位图对象 [英] Encode and decode bitmap object in base64 string in Android

查看:120
本文介绍了在Android中的base64字符串连接code和德code位图对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想EN code和德code 位图对象的字符串的base64 。我使用Android API10,

我都试过了,没有成功,以这种形式使用的方法来连接codeA 位图

 公共静态字符串连接codeTobase64(位图图像​​){
    位图immagex =图像;
    ByteArrayOutputStream BAOS =新ByteArrayOutputStream();
    immagex.com preSS(Bitmap.Com pressFormat.JPEG,100,BAOS);
    byte []的B = baos.toByteArray();
    字符串imageEn codeD = Base64.en codeToString(B,Base64.DEFAULT);

    Log.e(看,imageEn codeD);
    返回imageEn codeD;
}
 

解决方案

 公共静态字符串连接codeTobase64(位图图像​​)
{
    位图immagex =图像;
    ByteArrayOutputStream BAOS =新ByteArrayOutputStream();
    immagex.com preSS(Bitmap.Com pressFormat.JPEG,100,BAOS);
    byte []的B = baos.toByteArray();
    字符串imageEn codeD = Base64.en codeToString(B,Base64.DEFAULT);

    Log.e(看,imageEn codeD);
    返回imageEn codeD;
}
公共静态位图德codeBase64(字符串输入)
{
    byte []的德codedByte = Base64.de code(输入,0);
    返回BitmapFactory.de codeByteArray(德codedByte,0,德codedByte.length);
}
 

I want to encode and decode Bitmap object in string base64. I use the Android API10,

I have tried, with no success, to use a method in this form to encode a Bitmap.

public static String encodeTobase64(Bitmap image) {
    Bitmap immagex=image;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();  
    immagex.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    byte[] b = baos.toByteArray();
    String imageEncoded = Base64.encodeToString(b,Base64.DEFAULT);

    Log.e("LOOK", imageEncoded);
    return imageEncoded;
}

解决方案

public static String encodeTobase64(Bitmap image)
{
    Bitmap immagex=image;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();  
    immagex.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    byte[] b = baos.toByteArray();
    String imageEncoded = Base64.encodeToString(b,Base64.DEFAULT);

    Log.e("LOOK", imageEncoded);
    return imageEncoded;
}
public static Bitmap decodeBase64(String input) 
{
    byte[] decodedByte = Base64.decode(input, 0);
    return BitmapFactory.decodeByteArray(decodedByte, 0, decodedByte.length); 
}

这篇关于在Android中的base64字符串连接code和德code位图对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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