图片与Byte流互转

    public void  byteToImg(String bytes, String imagePath) throws IOException
    {
        
        byte[] buffer = Base64.decode(bytes);   //接收网络中的要进过解码
        File file = new File(SDPATH + imagePath);
        
        FileOutputStream fos = new FileOutputStream(file);

        fos.write(buffer);     
        
        fos.flush();

        fos.close();
        
        
    }
	public String imgToByte(String imagePath) throws IOException {

		BufferedInputStream in = new BufferedInputStream(new FileInputStream(
				SDPATH + imagePath));
		ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
		byte[] temp = new byte[1024];
		int size = 0;
		while ((size = in.read(temp)) != -1) {
			out.write(temp, 0, size);
		}
		 String uploadBuffer = new String(Base64.encode(out.toByteArray()));  //在网络传输中要进行Base64编码  接收端必然也要进行解码
		in.close();
		//byte[] content = out.toByteArray();
		return uploadBuffer;
	}

  

原文地址:https://www.cnblogs.com/gfqFighting/p/2477268.html