码迷,mamicode.com
首页 > 其他好文 > 详细

图片 Base64码 转换

时间:2015-10-13 10:26:27      阅读:246      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!