Android 台灣中文網

標題: 直接把串流下來的圖片存入SQL的方法 [打印本頁]

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





歡迎光臨 Android 台灣中文網 (https://apk.tw/) Powered by Discuz! X3.1