只需要传url即可
private static String strNetImageToBase64;
private String NetImageToBase64(String netImagePath) {
final ByteArrayOutputStream data = new ByteArrayOutputStream();
String s = null;
try {
URL url = new URL(netImagePath);
final byte[] by = new byte[1024];
final HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(5000);
new Thread(new Runnable() {
@Override
public void run() {
try {
InputStream is = conn.getInputStream();
int len = -1;
while ((len = is.read(by)) != -1) {
data.write(by, 0, len);
}
BASE64Encoder encoder = new BASE64Encoder();
strNetImageToBase64 = encoder.encode(data.toByteArray());
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
} catch (IOException e) {
e.printStackTrace();
}
return strNetImageToBase64;
}