img base64

<img src="data:image;base64,图片的base64编码">


 

用浏览器打开该html文件



 

Java将图片进行base64编码示例

/**
	 *  将图片转换为base64编码字符串
	 */
	public static String getImageStr(String imgFile) {
	    InputStream inputStream = null;
	    byte[] data = null;
	    try {
	        inputStream = new FileInputStream(imgFile);
	        data = new byte[inputStream.available()];
	        inputStream.read(data);
	        inputStream.close();
	    } catch (IOException e) {
	        e.printStackTrace();
	    }
	    // base64编码
	    BASE64Encoder encoder = new BASE64Encoder();
	    return encoder.encode(data);
	}

猜你喜欢

转载自huangqiqing123.iteye.com/blog/2361475