Android 台灣中文網
標題:
直接把串流下來的圖片存入SQL的方法
[打印本頁]
作者:
hl2dm
時間:
2013-1-16 16:33
標題:
直接把串流下來的圖片存入SQL的方法
我知道儲存圖片的方法一般為
String t1="http://www.xxx.xxx/xx/xx.jpg";
URL TKs = new URL(t1);
InputStream Is= TKs.openStream();
Bitmap Bp = BitmapFactory.decodeStream(Is);
Is.close();
複製代碼
如果是要把單機的圖片存入SQL中必須轉為byte(應該說任何檔案都能利用這個方法)
is = resources.openRawResource(R.drawable.xxx);
byte[] image2 = new byte[is.available()];
is.read(image2);
is.close();
複製代碼
於是我異想天開這樣寫
String t1="http://www.xxx.xxx/xx/xx.jpg";
URL TKs = new URL(t1);
InputStream Is= TKs.openStream();
byte[] image2 = new byte[Is.available()];
Is.read(image2);
Is.close();
複製代碼
結果byte變成空值orz
請問版友正確的方法該怎麼做呢?
歡迎光臨 Android 台灣中文網 (https://apk.tw/)
Powered by Discuz! X3.1