首页 > 其他 > 详细

图片 Base64码 转换

时间:2015-10-13 10:25:28      阅读:288      评论:0      收藏:0      [点我收藏+]

 

 

import sun.misc.BASE64Decoder;


    private String getBase64Picture(String imgBase64Str) {
        FileOutputStream fos = null;
        String uuid = UUID.randomUUID().toString();

        String staticPath = "d:/upsoft/test/img/";
        String relativePath = "/test/img/";

        File cutImgFile = new File(staticPath);
        if (!cutImgFile.exists()) {
            cutImgFile.mkdirs();
        }
        String picturePath = staticPath + uuid + ".jpg";
        try {
            byte[] fileDat = ImageStr2Bytes(imgBase64Str);
            File file = new File(picturePath);
            fos = new FileOutputStream(file);
            fos.write(fileDat);
            fos.close();

        } catch (Exception e) {
            e.printStackTrace();
        }
        return relativePath + uuid + ".jpg";
    }

    public byte[] ImageStr2Bytes(String imgStr) {
        BASE64Decoder decoder = new BASE64Decoder();
        try {
            byte[] b = decoder.decodeBuffer(imgStr);
            return b;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

 

图片 Base64码 转换

原文:http://www.cnblogs.com/vvonline/p/4873555.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!