开发者

Getting full-sized image from the camera does not work on Galaxy S

I am having a problem capturing an image from the built-in camera app on the Samsung Galaxy S.

I have a button on my app that when pressed launches the camera:

ContentValues values = new ContentValues();
values.put(Images.Media.MIME_TYPE, "image/jpeg");

mPicUri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);

intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, mPicUri.getPath());
startActivityForResult(intent, REQ_CODE_TAKE_PIC);

From what I read on the interwebz, I can get the full-sized just-taken picture using the URI I passed to the intent. And so I have this on my onActivityResult:

Uri selectedImage = mPicUri;
String[] filePathColumn = {MediaStore.Images.Media.DATA};

Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();

int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex);
cursor.close();

And then using the variable filePath, I set the image in an ImageView. I am getting no image, and when I stepped through the code, I found out that BitmapFactory.decodeFile() is returning null.

Bitmap chosenPic = BitmapFactory.decodeFile(filePath);

So I tried a little more debugging. I found out that mPicUri returns a seemingly valid URI, such as: content://media/external/images/media/90. After the picture is taken and the user chooses to save the picture, the cursor resolves to the following filePath: /sdcard/DCIM/Camera/1285601413961.jpg. No bitmap is decoded though, BUT when I looked through the gallery, the picture I just took is there. So I tried to take a look at the URI of that picture, and this is what I got:

URI is:           content://media/external/images/media/91
File path is:     /sdcard/DCIM/Camera/2010-09-27 23.30.30.jpg

And so, it looks like the value I got from mPicUri is not the final URI that will be used.

Am I missing a step here? All I really want to do is retrieve the 开发者_JAVA技巧file of the just-taken picture.

Thanks in advance, Zarah.


Did you try to specify File in both cases before taking picture and the same after?

public static File getTempFile() {
    //it will return /sdcard/image.jpg
    final File path = new File(Environment.getExternalStorageDirectory(), "MyApp");
    if (!path.exists()) {
        path.mkdir();
    }
    return new File(path, "image.jpg");
}

I'm using this function to get and set file path.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜