Retrieving byte[] of image using content provider

All your problems with Audio, Video and Images.

Retrieving byte[] of image using content provider

Postby prasadhari » Fri Jul 23, 2010 12:20 am

Hi,
TASK on hand:
1. Provide user ability to pick a graphic from either the SD card or capture one using camera
2. Get the byte[] of the selected image and save it in SQLIte DB along with the record it is linked to in the application.

Accomplished so far:
1. I have created a custom dialog for user to indicate if he intends to pick the image from SD card or want to click a snap.
2. Currently working on first option: Choose from SD Card
3. I use the following code to start INTENT
Code: Select all
public void onClick(View v) {
                  // TODO Auto-generated method stub
                  int requestCode = 1;
                  Intent i = new Intent(Intent.ACTION_PICK);
                  i.setData(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
                  startActivityForResult(i, requestCode);
                  dialog.cancel();
               }

4. On picking a graphic the control returns to
Code: Select all
public void onActivityResult(int requestCode, int resultCode, Intent outputIntent){
.
5. Now when i try to get byte[] of the selected graphic like below:
Code: Select all
                //Proceed to fetch the image and store it in DB
                Uri selectedUri = outputIntent.getData();
                //the output of the above statement from logs "URI:content://media/external/images/media/1"

      Cursor c = activity.getContentResolver().query(selectedUri, null, null, null, null);
                Bitmap img = BitmapFactory.decodeByteArray(c.getBlob(1), 0, data.length, null);


the img object is always NULL. I am stuck with this for a while now. Any help is appreciated. I have the following questsions:
1. I was able to get the column indices of the cursor and column names, but how do i get the type of each column?
2. I am doing something drastically wrong here?

Thanks
Hari
prasadhari
Freshman
Freshman
 
Posts: 4
Joined: Thu Jul 22, 2010 11:59 pm

Top

Re: Retrieving byte[] of image using content provider

Postby blundell » Fri Jul 23, 2010 1:48 pm

I have no experience in this area :-D

BUT

Have you debugged this in eclipse? You can then step through and view what objects are within the cursor object i.e. to check for your blob

my other idea was, you do c.getBlob(1) do you really want to do c.getBlob(0) :-D
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Re: Retrieving byte[] of image using content provider

Postby prasadhari » Fri Jul 30, 2010 1:04 am

I was able to resolve this.

Thanks
Hari
prasadhari
Freshman
Freshman
 
Posts: 4
Joined: Thu Jul 22, 2010 11:59 pm

Re: Retrieving byte[] of image using content provider

Postby blundell » Fri Jul 30, 2010 8:10 am

Can you share your answer / code fix. So anyone else coming across this thread has the answer please..
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 17 guests