0

这就是我成功获取应用程序的本机图标并首先显示它并最终将其作为 Blob 发送到数据库的方式:

Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("application_name");
            builder.setMessage("Vous avez cliqué sur : " + resolveInfo.activityInfo.name);
            Drawable iconApp;
            iconApp=resolveInfo.activityInfo.loadIcon(getPackageManager());

            BitmapDrawable bmd = (BitmapDrawable) iconApp;
            Bitmap bm = bmd.getBitmap();
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            bm.compress(Bitmap.CompressFormat.JPEG, 100, stream);
            byte[] bitmapdata = stream.toByteArray();
            SQLiteAdapter mySQLiteAdapter =new SQLiteAdapter(this.getApplicationContext());
            mySQLiteAdapter.openToWrite();
            String s=resolveInfo.activityInfo.name;
            mySQLiteAdapter.insertphoto(bitmapdata);
            mySQLiteAdapter.insert(s);

**我正试图找回它:**像这样:

SQLiteAdapter mySQLiteAdapter =new SQLiteAdapter(getApplicationContext());
                     mySQLiteAdapter.openToRead();
                     byte[] buffer = mySQLiteAdapter.queueAllphoto();
                     mySQLiteAdapter.close();

                     Drawable image = null;
                     image =  new BitmapDrawable(BitmapFactory.decodeByteArray(buffer, 0, buffer.length));
                     Bitmap b= convertByteArrayToBitmap(buffer);

                     //Bitmap bmp = BitmapFactory.decodeByteArray(content,0,content.length);

                     //image =  new BitmapDrawable(BitmapFactory.decodeByteArray(content, 0, content.length));
                     Builder builder = new AlertDialog.Builder(getBaseContext());
                     builder.setTitle("blob");
                     builder.setIcon(image);
                     builder.show();

最终这里是我的方法队列 SQliteAdapter 的所有照片部分:

public byte[] queueAllphoto(){
        String[] columns = new String[]{KEY_CONTENT_photo};
        Cursor cursor = sqLiteDatabase.query(MYDATABASE_TABLE_photo, columns, 
                null, null, null, null, null);
        byte[] result = null; 

        int index_CONTENT = cursor.getColumnIndex(KEY_CONTENT_photo);
        for(cursor.moveToFirst(); !(cursor.isAfterLast()); cursor.moveToNext()){
            result = cursor.getBlob(index_CONTENT) ;
        }

        return result;
    }

该方法返回一个字节数组,这是我想通过在 AlerDialogue 中显示每个 blob 来处理的字节数组!我正在努力将这个字节数组转换为可绘制对象,因为我正在考虑在 Builder 中使用它(AlertDialogue ) 使用方法 SetIcon(Drawable)

4

1 回答 1

1

通过更改返回类型(位图而不是字节数组)并添加 bitmap=BitmapFactory.decodeByteArray(result, 0, result.length) 我现在可以使用位图来更改 par 示例图像视图,如下所示:

 Bitmap bm = null;
                 SQLiteAdapter mySQLiteAdapter =new SQLiteAdapter(getApplicationContext());
                 mySQLiteAdapter.openToRead();
                 bm=mySQLiteAdapter.queueAllphoto();
                 mySQLiteAdapter.close();
                 imageview.setImageBitmap(bm);

在那里你得到了方法queueAllphoto():

公共位图 queueAllphoto(){

     Bitmap bitmap;

    String[] columns = new String[]{KEY_CONTENT_photo};
    Cursor cursor = sqLiteDatabase.query(MYDATABASE_TABLE_photo, columns, 
            null, null, null, null, null);
    byte[] result = null; 

    int index_CONTENT = cursor.getColumnIndex(KEY_CONTENT_photo);
    for(cursor.moveToFirst(); !(cursor.isAfterLast()); cursor.moveToNext()){
        result = cursor.getBlob(index_CONTENT) ;


    }

    bitmap=BitmapFactory.decodeByteArray(result, 0, result.length);
    return bitmap;
}
于 2013-02-05T10:45:57.317 回答