Android 根据所给的图片位置获得Thumbnail

public void listfiles(Activity act, File[] files) {

		ArrayList<HashMap<String, Object>> lstImageItem = new ArrayList<HashMap<String, Object>>();
		List<File> fileList = new ArrayList<File>();

		for (File file : files) {
			HashMap<String, Object> map = new HashMap<String, Object>();
			String thumbnail_path = null;
			// get the thumbnail of the given picture
			String[] projection2 = { "_id" }; // "_data"
			System.out.println("s");
			Uri uri2 = MediaStore.Images.Media.getContentUri("external");
			System.out.println("huhuhuhuhu" + file.getPath());
			String where = String.format("_data='%s'", "/mnt" + file.getPath());
			System.out.println(where);
			Cursor c2 = Media.query(act.getContentResolver(), uri2,
					projection2, where, null);
			if (c2.moveToFirst()) {
				do {
					long image_id = c2.getLong(c2.getColumnIndexOrThrow("_id"));
					System.out.println("------------------>" + image_id);
					String[] projection = { "_data" };
					Cursor c = Thumbnails.queryMiniThumbnail(
							act.getContentResolver(), image_id,
							Thumbnails.MINI_KIND, projection);
					if (c.moveToFirst()) {
						do {
							thumbnail_path = c.getString(c
									.getColumnIndexOrThrow("_data"));
							System.out.println("------------------>"
									+ thumbnail_path);
						} while (c.moveToNext());
					}
					// do some stuff
				} while (c2.moveToNext());
			}

			map.put("ItemImage", thumbnail_path);// 添加图像资源的ID
			// map.put("ItemText", "默认相册" + file.getName());// 按序号做ItemText
			lstImageItem.add(map);
			fileList.add(file);
		}
	}

你可能感兴趣的:(android)