在Android中的base64字符串连接code和德code位图对象位图、字符串、对象、Android

由网友(恶趣味大男孩)分享简介:我想EN code和德code 位图对象的字符串的base64 。我使用Android API10,我都试过了,没有成功,以这种形式使用的方法来连接codeA 位图。公共静态字符串连接codeTobase64(位图图像​​){位图immagex =图像;ByteArrayOutputStream BAOS =新Byte...

我想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);
}
 

vscode连接linux

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

阅读全文

相关推荐

最新文章