public static String encodeBase64(File targetFile) {
        BufferedImage image = null;

        try {
            image = ImageIO.read(targetFile);
        }
        catch (IOException e) {
            throw Lang.wrapThrow(e);
        }

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        BufferedOutputStream bos = new BufferedOutputStream(baos);
        image.flush();
        try {
            ImageIO.write(image, Files.getSuffixName(targetFile), bos);
            bos.flush();
            bos.close();
        }
        catch (IOException e) {
            throw Lang.wrapThrow(e);
        }

        byte[] bImage = baos.toByteArray();

        return Base64.encodeToString(bImage, false);
    }
public static String encodeBase64(File targetFile) {
        BufferedImage image = null;

        try {
            image = ImageIO.read(targetFile);
        }
        catch (IOException e) {
            throw Lang.wrapThrow(e);
        }

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        BufferedOutputStream bos = new BufferedOutputStream(baos);
        image.flush();
        try {
            ImageIO.write(image, Files.getSuffixName(targetFile), bos);
            bos.flush();
            bos.close();
        }
        catch (IOException e) {
            throw Lang.wrapThrow(e);
        }

        byte[] bImage = baos.toByteArray();

        return Base64.encodeToString(bImage, false);
    }
public static String encodeBase64 ( File targetFile ) { BufferedImage image = null ; try { image = ImageIO . read ( targetFile ) ; } catch ( IOException e ) { throw Lang . wrapThrow ( e ) ; } ByteArrayOutputStream baos = new ByteArrayOutputStream ( ) ; BufferedOutputStream bos = new BufferedOutputStream ( baos ) ; image . flush ( ) ; try { ImageIO . write ( image , Files . getSuffixName ( targetFile ) , bos ) ; bos . flush ( ) ; bos . close ( ) ; } catch ( IOException e ) { throw Lang . wrapThrow ( e ) ; } byte [ ] bImage = baos . toByteArray ( ) ; return Base64 . encodeToString ( bImage , false ) ; }
生成该图片对应的 Base64 编码的字符串

@param targetFile
图片文件
@return 图片对应的 Base64 编码的字符串
生成该图片对应的 Base64 编码的字符串