【问题标题】:Android storing image path in to SQLite DBAndroid将图像路径存储到SQLite DB
【发布时间】:2012-04-09 12:34:17
【问题描述】:

我正在开发一个打算将数据存储在 SQLIte 数据库中的应用程序。这是一种虚拟城市指南。
因此,我在数据库中存储了一些文本元素,我想将存储在设备中的图像和视频的路径存储在数据库的不同列和表中。

种类:

_ID INTEGER PRIMARY KEY AUTOINCREMENT (id of the image)
IMAGE_PATH TEXT UNIQUE (path of the image associated with the ID)

谁能举例说明我该怎么做?

【问题讨论】:

  • 你试过什么?展示一些代码的尝试,或搜索示例表明你已经完成了你的功课

标签: android image sqlite


【解决方案1】:

Bill Gary 的答案适用于一张图片,但因为我想做一个画廊,所以我使用了下面的代码:

this.imgPath = new String[mImageCursor.getCount()];

        int i = 0;

        while (mImageCursor.moveToNext()) {
            imgName = mImageCursor.getString(mImageCursor.getColumnIndex(MyDbAdapter.IMAGE_PATH));
            Log.w(TAG, baseDir + imgName);
            this.imgPath[i] = baseDir + imgName;
            Log.w(TAG, baseDir + mImageCursor.getString(mImageCursor.getColumnIndex(MyDbAdapter.IMAGE_PATH)) + " After");
            i++;
        }

        Gallery gallery = (Gallery) findViewById(R.id.VGgallery);
        gallery.setAdapter(new MyImageAdapter(this, this.imgPath));

希望对其他人有所帮助。

【讨论】:

    【解决方案2】:

    将路径存储为文本,当您在光标中获取路径时(例如变量 imagePath),使用此...

    imageResource = this.getResources().getIdentifier(
                    imagePath, null, null);
    ImageView.setImageResource(imageResource);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-22
      • 2013-12-04
      • 2015-02-27
      • 1970-01-01
      相关资源
      最近更新 更多