public static String getURLImage(String imageUrl) {
String base64String = "";
try {
URL url = new URL(imageUrl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(5 * 1000);
InputStream inStream = conn.getInputStream();
byte[] data = readInputStream(inStream);
BASE64Encoder encode = new BASE64Encoder();
base64String = "data:image/jpeg;base64," + encode.encode(data);
Log.e("tag===",base64String);
} catch (Exception e) {
e.printStackTrace();
}
return base64String;
}
private static byte[] readInputStream(InputStream inStream) throws Exception {
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = 0;
while ((len = inStream.read(buffer)) != -1) {
outStream.write(buffer, 0, len);
}
inStream.close();
return outStream.toByteArray();
}