[問題] Android的BitmapFactory.decodeByteArray
大家好!
我想把多張圖片分別轉成16進位的字串然後用"_"接起來回傳給我的Android
大概像 FFD8A9_FFD8D9_FFD8FF
圖一 圖二 圖三
因為之前合成一張JPEG的圖到Android程式去切聽說會很耗電
所以我想讓遠端的圖片轉成16進位的字串傳給我的Android程式
然後再把字串切開分別轉成Byte Array去做成圖
字串是PHP程式產生的 bin2hex(file_get_contents($img_path))
我的程式拿到字串後想轉成byte array,Google到程式碼
public byte[] Hex2BA(String in) {
byte[] b = new byte[in.length() / 2];
int i;
try {
for (i = 0; i <= in.length() / 2 - 1; i++) {
b[i] = (byte) Integer.parseInt(in.substring(2 * i, 2 * i + 2), 16);
}
} catch (Exception ex) {
return null;
}
return b;
}
轉完後用
BitmapFactory.decodeByteArray(bytesArr, 0, bytesArr.length);
得到的卻是null值,jpg跟bmp都試過,也試過帶option在decodeByteArray
弄了兩天還是弄不出來,來請教版上大大到底那裡出了問題,謝謝。
--
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.113.199.173
推
08/19 01:58, , 1F
08/19 01:58, 1F
→
08/19 02:11, , 2F
08/19 02:11, 2F
→
08/19 02:13, , 3F
08/19 02:13, 3F
→
08/19 02:15, , 4F
08/19 02:15, 4F