Does resource id changes everytime an application starts

前端 未结 3 982
后悔当初
后悔当初 2020-12-17 23:06

I am storing my images in drawable and their resource id in SQLite database.My database is created when the application starts for the first time.

Is it good to save

3条回答
  •  渐次进展
    2020-12-17 23:50

    It is Bad idea to store ids, But what is your purpose?? better idea is to store thumbnails to database rather than ids.. this helped me may this example help you do following steps

    1. get thumbnails of your image

      final int thumbnailSize = 128;// define your size

      Bitmap ThumbImage = ThumbnailUtils.extractThumbnail(BitmapFactory.decodeFile(imagePath), THUMBSIZE, THUMBSIZE);

    2. Convert it into Byte array

      Bitmap image = BitmapFactory.decodeResource(getResources(), R.drawable.thumbnail); ByteArrayOutputStream out = new ByteArrayOutputStream(); image.compress(Bitmap.CompressFormat.PNG, 100, out); byte[] buffer=out.toByteArray();

    3. Save it as Blob

      ContentValues cv=new ContentValues(); cv.put(CHUNK, buffer); //CHUNK blob type field of your table long rawId=database.insert(TABLE, null, cv); //TABLE table name

      I havnt used this but this may help you

提交回复
热议问题