Fork me on GitHub

Android开发之将图片文件转化为字节数组字符串,并对其进行Base64编码处理

作者:程序员小冰,CSDN博客:http://blog.csdn.net/qq_21376985

转载请说明出处。

/**
     * @将图片文件转化为字节数组字符串,并对其进行Base64编码处理
     * @author QQ986945193
     * @Date 2015-01-26
     * @param path 图片路径
     * @return
     */
    public static String imageToBase64(String path) {
    // 将图片文件转化为字节数组字符串,并对其进行Base64编码处理
        byte[] data = null;
        // 读取图片字节数组
        try {

            InputStream in = new FileInputStream(path);

            data = new byte[in.available()];

            in.read(data);

            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        // 对字节数组Base64编码
        BASE64Encoder encoder = new BASE64Encoder();
            // 返回Base64编码过的字节数组字符串
        return encoder.encode(data);

    }
posted @ 2016-07-01 10:21  程序员小冰  阅读(1614)  评论(0编辑  收藏  举报


Fork me on GitHub