解密。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
2条回答 默认 最新
关注 /** * 将图片文件转化为字节数组字符串,并对其进行Base64编码处理 * * @author linbingwen * @since 2016年3月30日 * @param imgFilePath 图片路径 * @return base64编码的字符串 * @throws IOException */ public static String imageToBase64(String imgFilePath) throws IOException { byte[] data = null; InputStream in = null; try { in = new FileInputStream(imgFilePath); data = new byte[in.available()]; // 读取图片字节数组 in.read(data); } catch (IOException e) { e.printStackTrace(); } finally { if (in != null) { in.close(); } } BASE64Encoder encoder = new BASE64Encoder();// 对字节数组Base64编码 return encoder.encode(data);// 返回Base64编码过的字节数组字符串 } /** * 对字节数组字符串进行Base64解码并生成图片 * * @author linbingwen * @since 2016年3月30日 * @param imgStr base64编码的数据 * @param imgFilePath 要保存的图片路径 * @param imgFileName 要保存的图片名 * @return * @throws IOException */ public static Boolean base64ToImage(String base64, String imgFilePath,String imgFileName) throws IOException { if (base64 == null) { return null; } BASE64Decoder decoder = new BASE64Decoder(); OutputStream out = null; try { byte[] bytes = decoder.decodeBuffer(base64);// Base64解码 for (int i = 0; i < bytes.length; ++i) { if (bytes[i] < 0) {// 调整异常数据 bytes[i] += 256; } } InputStream input = new ByteArrayInputStream(bytes); out = new FileOutputStream(imgFilePath + imgFileName);// 生成jpeg图片 out.write(bytes); out.flush(); return true; } catch (Exception e) { return false; } finally { if (out != null) { out.close(); } } }
解决 无用评论 打赏 举报
悬赏问题
- ¥15 求差集那个函数有问题,有无佬可以解决
- ¥15 【提问】基于Invest的水源涵养
- ¥20 微信网友居然可以通过vx号找到我绑的手机号
- ¥15 寻一个支付宝扫码远程授权登录的软件助手app
- ¥15 解riccati方程组
- ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
- ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
- ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
- ¥50 树莓派安卓APK系统签名
- ¥65 汇编语言除法溢出问题