我有以下代码(可在此网站的某个地方找到):
public static List<MyImages> getImages(Activity context) {
List<MyImages> lst = new ArrayList<MyImages>();
Cursor cursor = getCameraThumbImages(context);
if (cursor != null) {
int columnIndex = cursor
.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID);
int columnIndexPath = cursor
.getColumnIndexOrThrow(MediaStore.Images.Thumbnails.DATA);
int columnIndexImagePath = cursor
.getColumnIndexOrThrow(MediaStore.Images.Thumbnails.IMAGE_ID);
int count = cursor.getCount();
for (int i = 0; i < count; i++) {
cursor.moveToPosition(i);
int imageID = cursor.getInt(columnIndex);
String path = cursor.getString(columnIndexPath);
Uri imgThmbPath = Uri.withAppendedPath(
MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, ""
+ imageID);
String hope = cursor.getString(columnIndexImagePath);
MyImages p2p = new MyImages(path, "" + imageID);
lst.add(p2p);
}
}
return lst;
}
此代码使我可以访问手机上图像的缩略图.问题是我看不到如何从中获取原始图像路径.
问题是:给定缩略图(或光标),我如何获取原始图像路径?
解决方法:
在缩略图中,您具有MediaStore.Images.Thumbnails.IMAGE_ID字段,您可以从中获取相关的图像ID.比对MediaStore.Images.Media进行查询,并从MediaStore.Images.Media.DATA字段获取照片的路径.
编辑
// First request thumbnails what you want
String[] projection = new String[] {MediaStore.Images.Thumbnails._ID, MediaStore.Images.Thumbnails.IMAGE_ID};
Cursor thumbnails = contentResolver.query(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, projection, null, null, null);
// Then walk thru result and obtain imageId from records
for (thumbnails.moveToFirst(); !thumbnails.isAfterLast(); thumbnails.moveToNext()) {
String imageId = thumbnails.getString(thumbnails.getColumnIndex(Thumbnails.IMAGE_ID));
// Request image related to this thumbnail
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor images = contentResolver.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, filePathColumn, MediaStore.Images.Media._ID + "=?", new String[] {imageId}, null);
if (cursor != null && cursor.moveToFirst()) {
// Your file-path will be here
String filePath = cursor.getString(cursor.getColumnIndex(filePathColumn[0]));
}
}
//Of course you need to restrict queries using selection and selection args params and get only rows that you really need
标签:image-processing,android 来源: https://codeday.me/bug/20191201/2081253.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。