-1
我如何轉換的圖像(URL)立足64:轉換圖像與URL轉化基地64 +安卓
我嘗試以下,但它並沒有在工作
InputStream inputStream = null;
try {
inputStream = new BufferedInputStream(
new FileInputStream("https://blahblah/xyz.png"));
} catch (IOException e) {
e.printStackTrace();
}
byte[] bytes;
byte[] buffer = new byte[8192];
int bytesRead;
ByteArrayOutputStream output = new ByteArrayOutputStream();
try {
while ((bytesRead = inputStream.read(buffer)) != -1) {
output.write(buffer, 0, bytesRead);
}
} catch (IOException e) {
e.printStackTrace();
}
bytes = output.toByteArray();
String encodedImage = Base64.encodeToString(bytes, Base64.DEFAULT);
遇到錯誤先試試看。任何人都可以建議,可以做些什麼?
使用new URL("https://blahblah/xyz.png").openStream()
,它崩潰與以下錯誤:
android.os.NetworkOnMainThreadException
你也可以請出版堆棧跟蹤? – Sid
'image(含網址)'????什麼是帶有網址的圖片? – greenapps
請在這裏添加錯誤。 –