2017-10-30 3 views
0

BLOBをSQiteからStringに変換しました。その文字列をbyteArrayに変換したいが動作しません。私を助けてください。 ArrayListのHashMapの上の文字列へ文字列をBLOBから取得する場合、文字列をbyteArrayに変換する方法はありますか?

変換ブロブ:次のコードで

if (cursor.moveToFirst()) { 
     do { 
      HashMap<String, String> user = new HashMap<String, String>(); 
      user.put("username" , cursor.getString(9)); 
      user.put("photo" , cursor.getBlob(10).toString()); 
      ImageList.add(user); 
     } while (cursor.moveToNext()); 
    } 

私はImageViewの上で何を取得実行したとき、私は、私はByteArrayのに上記なった文字列を変換することができないよ:

ArrayList<HashMap<String, String>> photoList; 
    photoList = db.getString(); 
    HashMap<String, String> hashmap= photoList.get(0); 

    String photo_name = hashmap.get("photo"); 
    byte[] byteArray = photo_name.getBytes(); 

    Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length); 
    imageview.setImageBitmap(bmp); 
+1

BLOBSを使用するのは、アンチパターンです。イメージのパスを保存してストレージからロードする方がよいでしょう。 –

+0

@BernoulliGate、ありがとう、しかし、パスを使用することはできません。なぜなら、 'sqlite'にあるこのイメージは、mysqlからbase64として持ってきて、これをsqliteに格納したからです。それは –

答えて

-1
public class ConvertStringIntoBytes{ 

public void convertStringToByteArray() { 
    String stringToConvert = "This is test string"; 
    byte[] theByteArray = stringToConvert.getBytes(); 
    System.out.println(theByteArray.length); 
} 

public static void main(String[] args) { 
    new Main().convertStringToByteArray(); 
    } 
} 

文字列をバイト配列に変換するコード。

+0

@i貢献を感謝しない。ジャヤン・シャウハン –

関連する問題