图片转byte,String字符串转byte

/**
     * 图片转化成byte数组
     * @param bImage
     * @param format
     * @return
     */
       public byte[] imageToBytes(BufferedImage bImage, String format) {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try {
        ImageIO.write(bImage, format, out);
        } catch (IOException e) {
        e.printStackTrace();
        }
        return out.toByteArray();
        }
 

/**
 * 字符串转byte
 */
    public static byte[] strToByteArray(String str) {
        if (str == null) {
            return null;
        }
        byte[] byteArray = str.getBytes();
        return byteArray;
    }
 

猜你喜欢

转载自blog.csdn.net/qq_38819293/article/details/86525478