-
-
-
-
-
-
private
String Image2Base64(String imgUrl) {
-
URL url =
null
;
-
InputStream is =
null
;
-
ByteArrayOutputStream outStream =
null
;
-
HttpURLConnection httpUrl =
null
;
-
try
{
-
url =
new
URL(imgUrl);
-
httpUrl = (HttpURLConnection) url.openConnection();
-
httpUrl.connect();
-
httpUrl.getInputStream();
-
is = httpUrl.getInputStream();
-
-
outStream =
new
ByteArrayOutputStream();
-
-
byte
[] buffer =
new
byte
[
1024
];
-
-
int
len =
0
;
-
-
while
( (len=is.read(buffer)) != -
1
){
-
-
outStream.write(buffer,
0
, len);
-
}
-
-
return
new
BASE64Encoder().encode(outStream.toByteArray());
-
}
catch
(Exception e) {
-
e.printStackTrace();
-
}
下载
-
finally
{
-
if
(is !=
null
)
-
{
-
try
{
-
is.close();
-
}
catch
(IOException e) {
-
e.printStackTrace();
-
}
-
}
-
if
(outStream !=
null
)
-
{
-
try
{
-
outStream.close();
-
}
catch
(IOException e) {
-
e.printStackTrace();
-
}
-
}
-
if
(httpUrl !=
null
)
-
{
-
httpUrl.disconnect();
-
}
-
}
-
return
imgUrl;
-
}