如何在数据库中存储图像

时间:2011-08-05 01:41:52

标签: android database image

如何在互联网上存储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();
        }
    }

因此,对于所有标题,同一图像显示...我想为不同的标题显示不同的图像..

1 个答案:

答案 0 :(得分:1)

您必须使用图像名称作为服务器上的名称。 您必须使用目录

连接图像名称

例如

假设您有图像名称rose.jpg 如果你想把它保存在SD卡上,那么

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

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

String path = file.getAbsolutePath();
相关问题