2010-09-27 55 views
3
不工作我有从拍摄的图像问题

内置的三星Galaxy S.获得全尺寸图像上的Galaxy S

我有我的应用程序的按钮相机应用,按下启动相机时:

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); 

从我的趣闻阅读,我可以用我传递给意图的URI全尺寸刚刚拍摄的照片。所以我有这个在我的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(); 

,然后使用变量文件路径,我在ImageView的设置图像。我没有形象,当我通过代码时,我发现BitmapFactory.decodeFile()正在返回null

Bitmap chosenPic = BitmapFactory.decodeFile(filePath); 

所以我尝试了更多的调试。我发现mPicUri返回一个看起来有效的URI,例如:content://media/external/images/media/90。拍照并且用户选择保存图片后,光标会解析为以下文件路径:/sdcard/DCIM/Camera/1285601413961.jpg。虽然没有位图解码,但当我通过画廊看,我刚刚拍的照片就在那里。于是,我就看看这图片的URI,这是我得到了什么:

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

因此,它看起来像我从mPicUri得到的值不是最后 URI,这将是用过的。

我错过了一步吗?我真正想要做的就是检索刚刚拍摄的照片的文件。

在此先感谢, Zarah。

+0

有没有找到解决这个问题的办法? – 2011-09-30 20:02:04

+0

嗨@OhDannyBoy!对不起,暂时离开了StackOverflow。我想我想出了一个办法,必须在家检查我的代码。会让你知道! – Zarah 2011-10-05 02:32:41

+0

此资源具有检索图像的代码。 http://kevinpotgieter.wordpress.com/2011/03/30/null-intent-passed-back-on-samsung-galaxy-tab/但非常感谢您的帮助! – 2011-10-05 14:10:52

回答

0

您是否尝试在拍摄照片之前和之后的两种情况下指定File?

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"); 
} 

我正在使用此函数来获取和设置文件路径。