Android Base64字符串转换成图片

来源:互联网 发布:淘宝客佣金返回到哪里 编辑:程序博客网 时间:2024/06/02 18:28

转自:http://blog.sina.com.cn/s/blog_638686c601013xh0.html

public Bitmap stringtoBitmap(String string){
    //将字符串转换成Bitmap类型
    Bitmap bitmap=null;
    try {
    byte[]bitmapArray;
    bitmapArray=Base64.decode(string, Base64.DEFAULT);
bitmap=BitmapFactory.decodeByteArray(bitmapArray, 0, bitmapArray.length);
} catch (Exception e) {
e.printStackTrace();
}
   
    return bitmap;
    }
    
    
    
    public String bitmaptoString(Bitmap bitmap){

//将Bitmap转换成字符串
    String string=null;
    ByteArrayOutputStream bStream=new ByteArrayOutputStream();
    bitmap.compress(CompressFormat.PNG,100,bStream);
    byte[]bytes=bStream.toByteArray();
    string=Base64.encodeToString(bytes,Base64.DEFAULT);
    return string;
    }


原创粉丝点击