列出所有的Andr​​oid相机中的图像 [英] List all camera images in Android

查看:153
本文介绍了列出所有的Andr​​oid相机中的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你如何让Android设备的所有摄像机图像的列表?

How do you get a list of all camera images of an Android device?

它是通过MediaStore?怎么样?

Is it through the MediaStore? How?

推荐答案

画廊的应用程序获得相机图像用的内容解析的过<一个href="http://developer.android.com/reference/android/provider/MediaStore.Images.Media.html#EXTERNAL_CONTENT_URI">Images.Media.EXTERNAL_CONTENT_URI和过滤通过<一个结果href="http://developer.android.com/reference/android/provider/MediaStore.Images.ImageColumns.html#BUCKET_ID">Media.BUCKET_ID.铲斗标识符与以下$ C $下测定:

The Gallery app obtains camera images by using a content resolver over Images.Media.EXTERNAL_CONTENT_URI and filtering the results by Media.BUCKET_ID. The bucket identifier is determined with the following code:

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

在此基础上,这里有一个片段让所有摄像机图像:

Based on that, here's a snippet to get all camera images:

public static List<String> 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);
    ArrayList<String> result = new ArrayList<String>(cursor.getCount());
    if (cursor.moveToFirst()) {
        final int dataColumn = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        do {
            final String data = cursor.getString(dataColumn);
            result.add(data);
        } while (cursor.moveToNext());
    }
    cursor.close();
    return result;
}

有关更多信息,请查看的照片应用程序源$ C ​​$ c中的ImageManager和ImageList的类。

For more info, review the ImageManager and ImageList classes of the Gallery app source code.

这篇关于列出所有的Andr​​oid相机中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆