2016-06-15 9 views
2

私のアプリケーションで私はイメージを格納するデータベースを持っています.iはイメージを取得したいと思います。イメージは簡単にBitMapで取得しますが、どのようにビットマップイメージを整数フォーマットに変換できますか?整数配列へのビットマップ?

これはコードである:

DataBaseClass objOfDataBaseClass=new DataBaseClass(context); 
    Cursor mCursor=objOfDataBaseClass.showData();//here is all data taken from dataBase 

if(mCursor.moveToNext()) { 

     byte[] mg=null; 
     mg = mCursor.getBlob(mCursor.getColumnIndex("image")); 
     Bitmap bitmap = BitmapFactory.decodeByteArray(mg, 0, mg.length); 

     int[] store=?//how can i bitMap store in this array. 
} 

答えて

1

ビットマップは画像を含んでいるようにあなたは、ビットマップ自体の画素を格納するべきではないBitmap.getPixels方法(documentation

int width = bitmap.getWidth(); 
int height = bitmap.getHeight(); 
int[] store = new int[width * height]; 
bitmap.getPixels(store, 0, width, 0, 0, width, height); 
1

を使用することができ圧縮されていないフォームを作成した場合、膨大な量のデータが生成されます(1024 x 768 x 32ビットは3.1 MB)。

ビットマップをビットマップによりよく圧縮します。 PNGを作成し、データベースに格納します。その目的でBitmap.compress()を使用し、ByteArrayOutputStreamを使用してデータを書き込むことができます。次に、その出力ストリームのバイトをデータベースに格納します。

関連する問題