【问题标题】:how to store images in database如何将图像存储在数据库中
【发布时间】:2011-08-05 01:41:51
【问题描述】:

如何将来自互联网的多个图像存储在 sdcard 中并将路径存储在数据库中?对于多张图片,我该怎么办?到目前为止,我所做的是..

表创建查询如下:

"create table table1 (_id integer primary key autoincrement, " 
                  + "title text not null, definition text not null, image BLOB not null);";

但是为了存储我插入的一个值

        bmOptions = new BitmapFactory.Options();
        bmOptions.inSampleSize = 1;
        bm = Loadmage(image_URL, bmOptions);

        mImageV.setImageBitmap(bm);


      extStorageDirectory = Environment.getExternalStorageDirectory().toString();

        OutputStream outStream = null;
           File file = new File(extStorageDirectory, "er.PNG");
           try{
            outStream = new FileOutputStream(file);
            bm.compress(Bitmap.CompressFormat.PNG, 100, outStream);
            outStream.flush();
            outStream.close();
           }catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
           } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

所以对于所有标题显示相同的图像...我想为不同的标题显示不同的图像..

【问题讨论】:

  • 在数据库中为每条记录存储一个路径有问题吗?也许您需要问题中的更多细节,例如您的数据库表是什么样的。

标签: android database image


【解决方案1】:

您必须使用图像的名称作为服务器名称。 您只需将图像名称与目录连接起来

例如

假设您的图像名称为rose.jpg 如果你想把它保存在 SD 卡上然后

File file = new File(Environment.getExternalStorageDirectory(), "/backup/" + rose.jpg);

然后您可以存储文件名的路径,如

String path = file.getAbsolutePath();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-03-10
    • 2012-06-08
    • 1970-01-01
    • 2012-10-17
    相关资源
    最近更新 更多