1

電話内にいくつかの画像を保存し、画像パスをデータベースに挿入しました。データベース内の画像パスを使用して、グリッドビューに表示したかったのです。今のところ、ギャラリーアプリで画像を表示するグリッドビューを作成できます。しかし、データベースパスに基づいて画像を表示する方法はよくわかりません。可能であれば、誰かがこの問題について私に教えてもらえますか?コメントをいただければ幸いです。

以下のコードは、ギャラリーに画像を表示するために使用しました。

    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.phone_tab);

    final String[] columns = { MediaColumns.DATA, BaseColumns._ID };
    final String orderBy = BaseColumns._ID;
    Cursor imagecursor = managedQuery(
            MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns, null,
            null, orderBy);
    int image_column_index = imagecursor.getColumnIndex(BaseColumns._ID);
    this.count = imagecursor.getCount();
    this.thumbnails = new Bitmap[this.count];
    this.arrPath = new String[this.count];
    this.thumbnailsselection = new boolean[this.count];
    for (int i = 0; i < this.count; i++) {
        imagecursor.moveToPosition(i);
        int id = imagecursor.getInt(image_column_index);
        int dataColumnIndex = imagecursor.getColumnIndex(MediaColumns.DATA);
        thumbnails[i] = MediaStore.Images.Thumbnails.getThumbnail(
                getApplicationContext().getContentResolver(), id,
                MediaStore.Images.Thumbnails.MICRO_KIND, null);
        arrPath[i]= imagecursor.getString(dataColumnIndex);
    }
    GridView imagegrid = (GridView) findViewById(R.id.PhoneImageGrid);
    imageAdapter = new ImageAdapter();
    imagegrid.setAdapter(imageAdapter);
    imagecursor.close();

    final Button selectBtn = (Button) findViewById(R.id.select_btn);
    selectBtn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            final int len = thumbnailsselection.length;
            int cnt = 0;
            String selectImages = "";
            for (int i =0; i<len; i++)
            {
                if (thumbnailsselection[i]){
                    cnt++;
                    selectImages = selectImages + arrPath[i] + "|";
                }
            }
            if (cnt == 0){
                Toast.makeText(getApplicationContext(),
                        "Please select at least one image",
                        Toast.LENGTH_LONG).show();
            } else {
                Toast.makeText(getApplicationContext(),
                        "You've selected Total " + cnt + " image(s).",
                        Toast.LENGTH_LONG).show();
                Log.d("SelectedImages", selectImages);

                Intent input = new Intent(v.getContext(), InputScreen.class);
                input.putExtra("selectImages", selectImages+"");
                StringBuffer urlString = new StringBuffer();
                replaceContentView("InputScreen", input);

            }


        }



    });



}

値[2]は/mnt/sdcard/ImageFolder/Image1.jpgとして返されます。

    String values[] = helper.get_user_image(useremail);
    String filepath = values[2];
4

1 に答える 1

0

データベースに画像ではなく画像パスを保存する方が良いです。データベースに保存されている画像パスを使用してこれらの画像にアクセスします。

データベースで画像を使用する必要がある場合

  • バイト配列の代わりに Stream を使用してください

次のリソースが役立つ場合があります

于 2012-12-20T06:18:04.647 に答える