图片转流

    /**
     * 图片转流
     *
     * @param imgpath
     * @return
     * @throws Exception
     */
    public String byte2Base64String(String imgpath) throws Exception {
        byte[] buffer = null;
        if (null != imgpath && !"".equals(imgpath.toString().trim())) {
            File file = new File(imgpath);
            FileInputStream fis = new FileInputStream(file);
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            byte[] b = new byte[1024];
            int n;
            while ((n = fis.read(b)) != -1) {
                bos.write(b, 0, n);
            }
            fis.close();
            bos.close();
            buffer = bos.toByteArray();
            Blob serialBlob = new SerialBlob(buffer);
            InputStream binaryStream = serialBlob.getBinaryStream();
            byte[] input2byte = FileUtil.input2byte(binaryStream);
            String imageString = ImageUtil.imageByte2String(input2byte);
            return imageString;
        } else {
            return null;
        }
    }
原文地址:https://www.cnblogs.com/diandianquanquan/p/10640667.html