BASE64加密图片字符串转码
2016-01-06 17:20
260 查看
前段自己遇到了BASE64图片字符串加密转码相关的问题,网上一搜,貌似都差不多,但是有的却是不能使用,要么导入jar有问题,要么就是导入路径不存在,也搜索了半天,总算是解决了,现在贴出代码,方便自己以后使用,也方便他人,虽然自己是小菜菜,但是我还在路上呢嘛,贴上代码。
参数为Bitmap:
参数为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(); }
相关文章推荐
- 读<看透Spring MVC 源代码分析与实践>Tomcat笔记
- return与finally
- Linux下shell的学习--之杂七杂八
- ubuntu 安装jre错误
- leetcode之Linked List Cycle
- 巧用 adb logcat
- 网络编程基础
- Spring mvc的整体流程(二)
- iOS中const与static区别和联系
- CAST,CONVERT,
- Android常见的按钮监听器实现
- 轻松学习之Linux教程一 ubuntu14.04+windows双系统安装
- 十进制数的运算规则 C语言
- ASP.NET(C#)——DataList控件——商品展示
- 【bzoj2749】【HAOI2012】【外星人】【数论】
- runtime之自学
- 链表,队列,堆栈的区别
- Word自动目录字体过大,如何全选并修改样式
- unity模型部分替换
- mysql-mysql悲观锁和乐观锁