我很好奇如何从Android的图库/相机文件夹中获取图像。我正在查看文件管理器,无法真正掌握这些映像在文件系统中的位置。如果我去文件管理器,我找不到拍摄照片的确切位置。如果我去画廊应用程序,我看到他们挂在“相机”文件夹。android - 从相机拍摄图像
一些关于我试图做到:
得到所有现有的照片,保存在某些时候和我的活动显示它们。我正在尝试允许电话用户从现有照片中为他们的个人资料分配头像。
我很好奇如何从Android的图库/相机文件夹中获取图像。我正在查看文件管理器,无法真正掌握这些映像在文件系统中的位置。如果我去文件管理器,我找不到拍摄照片的确切位置。如果我去画廊应用程序,我看到他们挂在“相机”文件夹。android - 从相机拍摄图像
一些关于我试图做到:
得到所有现有的照片,保存在某些时候和我的活动显示它们。我正在尝试允许电话用户从现有照片中为他们的个人资料分配头像。
这里是代码,以防有人需要它。这是在姜饼上进行测试。
List<Image> existingPhotos = getCameraImages(this);
photosGrid = (GridView)findViewById(R.id.gvExistingPhotos);
LazyPhotosGridAdapter adapter = new LazyPhotosGridAdapter(this, existingPhotos);
photosGrid.setAdapter(adapter);
public String getRealPathFromURI(Uri contentUri) {
String[] proj = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(contentUri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
public static List<Image> getCameraImages(Context context) {
final String[] projection = { MediaStore.Images.Media.DATA };
final String selection = MediaStore.Images.Media.BUCKET_ID + " = ?";
final String[] selectionArgs = { CAMERA_IMAGE_BUCKET_ID };
final Cursor cursor = context.getContentResolver().query(Images.Media.EXTERNAL_CONTENT_URI,
projection,
selection,
selectionArgs,
null);
List<Image> result = new ArrayList<Image>(cursor.getCount());
if (cursor.moveToFirst()) {
final int dataColumn = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
do {
final String data = cursor.getString(dataColumn);
result.add(new Image(data));
} while (cursor.moveToNext());
}
cursor.close();
return result;
}
public static final String CAMERA_IMAGE_BUCKET_NAME =
Environment.getExternalStorageDirectory().toString()
+ "/DCIM/Camera";
public static final String CAMERA_IMAGE_BUCKET_ID =
getBucketId(CAMERA_IMAGE_BUCKET_NAME);
/**
* Matches code in MediaProvider.computeBucketValues. Should be a common
* function.
*/
public static String getBucketId(String path) {
return String.valueOf(path.toLowerCase().hashCode());
}
[列表中所有的Android相机图像]的
这是完全错误的,其他类似的答案也是如此。并非所有手机都将照片保存到“/ DCIM/Camera”文件夹。例如,Sony Xperia L使用“/ DCIM/100ANDRO”,我猜“100”部分有时会增加。 – 2014-05-16 14:14:09
This answer可能会有所帮助。这是一个常见问题,因此如果您搜索了StackOverflow的Android camera,您可能会得到结果。
公顷,是的,对不起我没有”实现其相同的代码。我在几天前发现了相同的帖子:)欣赏帮助。 – dropsOfJupiter 2011-03-17 21:53:26
可能重复(http://stackoverflow.com/questions/4484158/list-all-camera-images-in-android) – 2011-03-15 17:32:09