BASE64加密图片字符串转码

前段自己遇到了BASE64图片字符串加密转码相关的问题,网上一搜,貌似都差不多,但是有的却是不能使用,要么导入jar有问题,要么就是导入路径不存在,也搜索了半天,总算是解决了,现在贴出代码,方便自己以后使用,也方便他人,虽然自己是小菜菜,但是我还在路上呢嘛,贴上代码。

参数为Bitmap:

/* ~ BASE64 转码****** */
public static String toBase64Encode(Bitmap msg) {

ByteArrayOutputStream baos = new ByteArrayOutputStream();
msg.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte b [] = baos.toByteArray();

return Base64.encodeToString(b, Base64.DEFAULT);

}
参数为String:
/* ~ BASE64 转码****** */
public static String toBase64Encode(String msg) {

return Base64.encodeToString(msg.getBytes(), Base64.DEFAULT);

}


/* ~ BASE64 解码****** */
public static String toBase65Decode(String msg) {
/* ~ base64解析******** */
byte[] msgCode = Base64.decode(msg, Base64.DEFAULT);
String content = new String(msgCode);
return content;

}
顺便加上获取后缀名的,当然还有对后缀名判断的,工程在家里,有时间考上

/**
* 
* 获取后缀名
* 
* //img_path.lastIndexOf(".")返回最后一次出现的.在此字符串中的索引。
* //img_path.substring(img_path.lastIndexOf(".") + 1)返回一个新的字符串 //trim()清空空格
* //toLowerCase()转化成小写
* 
* @参数: @param img_path
* @参数: @return
* @return String
* @throws
*/
public static String getPicSuffix(String img_path) {
if (img_path == null || img_path.indexOf(".") == -1) {
return ""; // 如果图片地址为null或者地址中没有"."就返回""
}
return img_path.substring(img_path.lastIndexOf(".") + 1).trim()
.toLowerCase();
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值