Sahil Jain Sahil Jain - 12 days ago 6
Android Question

How to get URL for an image stored in database in BLOB format

I'm saving image in wamp database. How to get it's URL so that I can use that URL in my android program for displaying that image?

Answer
  public Bitmap getCurrentBitmap() {
        SQLiteDatabase db       =   dbs.getWritableDatabase();
        String sql              =   "SELECT * FROM Image";// SELECT blob image column.
        Cursor cursor           =   db.rawQuery(sql, new String[]{});
        Bitmap bmp=null;
        if(cursor.moveToFirst()){
            //this.accId             = cursor.getInt(0);
          //  this.accName           = cursor.getString(1);
            byte[] logoImage       = cursor.getBlob(1);// get blob image convert into byte array[]

         Bitmap    bmp = BitmapFactory.decodeByteArray(logoImage, 0, logoImage.length);// now convert into Bitmap
        }
        if (cursor != null && !cursor.isClosed()) {
            cursor.close();
        }
        db.close();
        if(cursor.getCount() == 0){
            return null;
        } else {
            return bmp;
        }
    }

// To show images

  profile_images.setImageBitmap(getCurrentBitmap());