0

Is it possible to load an image from its path saved in the database. The image is actually saved in the sd card (the default gallery).

This is the path of the image saved in the database

/mnt/sdcard/download/68107_174917912527848_100000289204785_530969_2619951_n-1.jpg

I want to load this image on an image view when an activity starts.

batman567
  • 826
  • 2
  • 12
  • 23
Marque
  • 23
  • 2
  • 8

2 Answers2

1

Fetch Image path from database using select query,

then ,

Bitmap bitmap = BitmapFactory.decodeFile(<pathOfImage>);
ImageView img = new ImageView(this);
img.setImageBitmap(bitmap);
user370305
  • 108,599
  • 23
  • 164
  • 151
  • ya. But isn't it necessary to use ImageView user=(ImageView)findViewById(R.id.imageView1) – Marque Nov 16 '11 at 11:35
  • ya now the way i did it is as you said ImageView user; Bitmap bitmap = BitmapFactory.decodeFile(loc); user=(ImageView)findViewById(R.id.imageView1); user.setImageBitmap(bitmap); – Marque Nov 16 '11 at 11:40
  • But it is not getting displayed – Marque Nov 16 '11 at 11:41
  • I am not getting anything displayed... loc is a string to which I have assigned the value of that path – Marque Nov 16 '11 at 11:44
  • yeah it exists.. i have checked – Marque Nov 16 '11 at 11:47
  • The reason why I assigned it to a string is coz I have provided an option to change the pic in which i can select pic from gallery and display it. – Marque Nov 16 '11 at 11:52
  • thanks but what should i do if i want to change the pic as i mentioned – Marque Nov 16 '11 at 11:55
  • hey thats not the thing.. I am saving the location in the db. Then I select the value using select query and I assigned that loc variable with the value that was selected using cursor Cursor c1 = sampleDB.rawQuery("SELECT * FROM USER_PROFILE WHERE user_id='1'", null); String loc=c1.getString(c1.getColumnIndex("user_picture")); – Marque Nov 16 '11 at 12:02
  • yeah... i its working the way u said. But how can I change the image ? I cannot assign a value directly to the loc string coz it will change when i select another picture – Marque Nov 16 '11 at 12:08
  • yes i have done that. But I am not getting a way to change the pic. Can please help me on that too. – Marque Nov 16 '11 at 12:14
  • Now, using your code just put Bitmap bitmap = BitmapFactory.decodeFile(""+loc); and let me know what happen. – user370305 Nov 16 '11 at 12:21
  • sorry to respond late. But i got it....The reason was the position where I had placed the code – Marque Nov 17 '11 at 05:02
1

Its like reading any other file from sdcard, you can use BitmapFactory to convert File into bitmap and use it in imageview,

Check this,
Show Image View from file path?

Community
  • 1
  • 1
sat
  • 40,138
  • 28
  • 93
  • 102