/** * 得到缩略图 */ private static HashMap<String, String> getThumbnail(ContentResolver cr) { String[] projection = {Thumbnails._ID, Thumbnails.IMAGE_ID, Thumbnails.DATA}; Cursor cursor = cr.query(Thumbnails.EXTERNAL_CONTENT_URI, projection, null, null, null); HashMap<String, String> thumbnailList = new HashMap<String, String>(); if (cursor.moveToFirst()) { int image_id; String image_path; int image_idColumn = cursor.getColumnIndex(Thumbnails.IMAGE_ID); int dataColumn = cursor.getColumnIndex(Thumbnails.DATA); do { image_id = cursor.getInt(image_idColumn); image_path = cursor.getString(dataColumn); thumbnailList.put("" + image_id, image_path); } while (cursor.moveToNext()); cursor.close(); } return thumbnailList; }
/** * 从数据库中得到缩略图 * * @param cur */ private void getThumbnailColumnData(Cursor cur) { if (cur.moveToFirst()) { // int _id; int image_id; String image_path; // int _idColumn = cur.getColumnIndex(Thumbnails._ID); int image_idColumn = cur.getColumnIndex(Thumbnails.IMAGE_ID); int dataColumn = cur.getColumnIndex(Thumbnails.DATA); do { // Get the field values // _id = cur.getInt(_idColumn); image_id = cur.getInt(image_idColumn); image_path = cur.getString(dataColumn); thumbnailList.put("" + image_id, image_path); } while (cur.moveToNext()); cur.close(); } }
/** * 得到缩略图 */ private void getThumbnail() { String[] projection = { Thumbnails._ID, Thumbnails.IMAGE_ID, Thumbnails.DATA }; Cursor cursor = null; try { cursor = contentResolver.query(Thumbnails.EXTERNAL_CONTENT_URI, projection, null, null, null); getThumbnailColumnData(cursor); } catch (Exception e) { logger.e(e.getMessage()); } finally { if (null != cursor) { cursor.close(); } } }
/** * 从数据库中得到缩略图 * * @param cur */ private void getThumbnailColumnData(Cursor cur) { try { if (null == cur) return; if (cur.moveToFirst()) { @SuppressWarnings("unused") int cId; int image_id; String image_path; int _idColumn = cur.getColumnIndex(Thumbnails._ID); int image_idColumn = cur.getColumnIndex(Thumbnails.IMAGE_ID); int dataColumn = cur.getColumnIndex(Thumbnails.DATA); do { cId = cur.getInt(_idColumn); image_id = cur.getInt(image_idColumn); image_path = cur.getString(dataColumn); thumbnailList.put("" + image_id, image_path); } while (cur.moveToNext()); } } catch (Exception e) { logger.e(e.getMessage()); } }
@Override protected Object doInBackground(FileItem... params) { Bitmap bitmap = null; // 鑾峰彇瑙嗛鐨勭缉鐣ュ浘 FileItem item = params[0]; bitmap = ThumbnailUtils.createVideoThumbnail(item.getFilePath(), Thumbnails.MICRO_KIND); bitmap = ThumbnailUtils.extractThumbnail(bitmap, width, height, ThumbnailUtils.OPTIONS_RECYCLE_INPUT); if (bitmap != null) { item.setIcon(bitmap); publishProgress(); return bitmap; } else { return null; } }
private Bitmap getThumbnailImageFromMediaStore(Context context) { Resources res = context.getResources(); final int kind = Thumbnails.MINI_KIND; BitmapFactory.Options opts = new BitmapFactory.Options(); opts = new BitmapFactory.Options(); try { final long id = Long.parseLong(getOriginalPhotoUri() .getLastPathSegment()); Bitmap bitmap = Thumbnails.getThumbnail( context.getContentResolver(), id, kind, opts); bitmap = Utils.rotate(bitmap, getExifRotation(context)); return bitmap; } catch (Exception e) { return null; } }
private void getThumbnailColumnData(Cursor cur) { mThumbnailList.clear(); if (cur.moveToFirst()) { int image_id; int image_idColumn = cur.getColumnIndex(Thumbnails.IMAGE_ID); int dataColumn = cur.getColumnIndex(Thumbnails.DATA); String image_path; do { image_id = cur.getInt(image_idColumn); image_path = cur.getString(dataColumn); mThumbnailList.put("" + image_id, image_path); } while (cur.moveToNext()); } }
private void getThumbnailColumnData(Cursor cur) { if (cur.moveToFirst()) { int _id; int image_id; String image_path; int _idColumn = cur.getColumnIndex(Thumbnails._ID); int image_idColumn = cur.getColumnIndex(Thumbnails.IMAGE_ID); int dataColumn = cur.getColumnIndex(Thumbnails.DATA); do { // Get the field values _id = cur.getInt(_idColumn); image_id = cur.getInt(image_idColumn); image_path = cur.getString(dataColumn); // Do something with the values. // Log.i(TAG, _id + " image_id:" + image_id + " path:" // + image_path + "---"); // HashMap<String, String> hash = new HashMap<String, String>(); // hash.put("image_id", image_id + ""); // hash.put("path", image_path); // thumbnailList.add(hash); thumbnailList.put("" + image_id, image_path); } while (cur.moveToNext()); } }
private void getVideoThumbnail() { String[] thumbColumns = { MediaStore.Video.Thumbnails.DATA, MediaStore.Video.Thumbnails.VIDEO_ID }; // 视频其他信息的查询条件 String[] mediaColumns = { MediaStore.Video.Media._ID, MediaStore.Video.Media.DATA, MediaStore.Video.Media.DURATION }; Cursor cursor = cr.query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, mediaColumns, null, null, null); if (null != cursor) { if (cursor.moveToFirst()) { do { int id = cursor.getInt(cursor.getColumnIndex(MediaStore.Video.Media._ID)); Cursor thumbCursor = cr.query(MediaStore.Video.Thumbnails.EXTERNAL_CONTENT_URI, thumbColumns, MediaStore.Video.Thumbnails.VIDEO_ID + "=" + id, null, null); if (thumbCursor.moveToFirst()) { String thumbnails = thumbCursor.getString(thumbCursor.getColumnIndex(MediaStore.Video.Thumbnails.DATA)); // ThumbnailUtils.createVideoThumbnail(thumbnails, // kind); thumbnailList.put("" + id, thumbnails); } } while (cursor.moveToNext()); } cursor.close(); } }
public void getThumbnails() { ContentResolver cr = getContentResolver(); String[] projection = { Thumbnails._ID, Thumbnails.IMAGE_ID, Thumbnails.DATA }; Cursor cur = cr.query(Thumbnails.EXTERNAL_CONTENT_URI, projection, null, null, null); if (cur.moveToFirst()) { int _id; int image_id; String image_path; int _idColumn = cur.getColumnIndex(Thumbnails._ID); int image_idColumn = cur.getColumnIndex(Thumbnails.IMAGE_ID); int dataColumn = cur.getColumnIndex(Thumbnails.DATA); do { // Get the field values _id = cur.getInt(_idColumn); image_id = cur.getInt(image_idColumn); image_path = cur.getString(dataColumn); // Do something with the values. Log.e(TAG, _id + " image_id:" + image_id + " path:" + image_path + "---"); } while (cur.moveToNext()); } }
/** * 创建图片缩略图集合 */ private void createThumbnails(){ Cursor cursor = mContentResolver.query(Thumbnails.EXTERNAL_CONTENT_URI, THUMBNAILS_PROJECTTION, null, null, null); if (cursor.moveToFirst()) { int id; String data; int idIndex = cursor.getColumnIndex(Thumbnails.IMAGE_ID); int dataIndex = cursor.getColumnIndex(Thumbnails.DATA); thumbnails.clear(); do{ id = cursor.getInt(idIndex ); data = cursor.getString(dataIndex); thumbnails.put(String.valueOf(id), data); }while(cursor.moveToNext()); } cursor.close(); }
public static Uri getBitmapFromImageId(Activity activity, int imageId) { String[] tinyImgPprojection = { MediaStore.Images.Thumbnails._ID }; Cursor tinyCursor = Thumbnails.queryMiniThumbnail( activity.getContentResolver(), imageId, Thumbnails.MINI_KIND, tinyImgPprojection); if (tinyCursor.getCount() != 0) { tinyCursor.moveToFirst(); int tinyImgId = tinyCursor.getInt(tinyCursor .getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID)); tinyCursor.close(); return Uri.withAppendedPath( MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, String.valueOf(tinyImgId)); } else { tinyCursor.close(); return null; } }
/** * 得到缩略图 */ private void getThumbnail() { String[] projection = {Thumbnails._ID, Thumbnails.IMAGE_ID, Thumbnails.DATA}; Cursor cursor = cr.query(Thumbnails.EXTERNAL_CONTENT_URI, projection, null, null, null); getThumbnailColumnData(cursor); }
/** * * 通过ContentResolver查找本地图库照片的url * * @LastModifiedDate:2013-12-6 * @author he */ private static void findimagepath(Context mContext) { list = new ArrayList<String>(); ContentResolver cr = mContext.getContentResolver(); String[] imagedata = { Thumbnails._ID, Thumbnails.IMAGE_ID, Thumbnails.DATA };// 找到image Cursor cursor = cr.query(Thumbnails.EXTERNAL_CONTENT_URI, imagedata, null, null, null); // 利用游标找image getColumnData(cursor); }
/** * * 通过解析游标拿取实际的值 * * @author he */ private static void getColumnData(Cursor cur) { if (cur.moveToFirst()) { String image_path; int dataColumn = cur.getColumnIndex(Thumbnails.DATA); do { image_path = cur.getString(dataColumn); list.add(image_path); } while (cur.moveToNext()); } }
private void getThumbnail() { String[] projection = { Thumbnails._ID, Thumbnails.IMAGE_ID, Thumbnails.DATA }; Cursor cursor = cr.query(Thumbnails.EXTERNAL_CONTENT_URI, projection, null, null, null); getThumbnailColumnData(cursor); }
public static Bitmap getVideotThumbnail(String path, int width, int height) { Bitmap srcBitmap = ThumbnailUtils.createVideoThumbnail(path, Thumbnails.FULL_SCREEN_KIND); Bitmap targetedbitmap = ThumbnailUtils.extractThumbnail(srcBitmap, width, height, ThumbnailUtils.OPTIONS_RECYCLE_INPUT); return targetedbitmap; }
/** * �õ�����ͼ */ private void getThumbnail() { String[] projection = { Thumbnails._ID, Thumbnails.IMAGE_ID, Thumbnails.DATA }; Cursor cursor = cr.query(Thumbnails.EXTERNAL_CONTENT_URI, projection, null, null, null); getThumbnailColumnData(cursor); }
/** * �����ݿ��еõ�����ͼ * * @param cur */ private void getThumbnailColumnData(Cursor cur) { if (cur.moveToFirst()) { int _id; int image_id; String image_path; int _idColumn = cur.getColumnIndex(Thumbnails._ID); int image_idColumn = cur.getColumnIndex(Thumbnails.IMAGE_ID); int dataColumn = cur.getColumnIndex(Thumbnails.DATA); do { // Get the field values _id = cur.getInt(_idColumn); image_id = cur.getInt(image_idColumn); image_path = cur.getString(dataColumn); // Do something with the values. // Log.i(TAG, _id + " image_id:" + image_id + " path:" // + image_path + "---"); // HashMap<String, String> hash = new HashMap<String, String>(); // hash.put("image_id", image_id + ""); // hash.put("path", image_path); // thumbnailList.add(hash); thumbnailList.put("" + image_id, image_path); } while (cur.moveToNext()); } }
/** * 从数据库中得到缩略图 * * @param cur */ private void getThumbnailColumnData(Cursor cur) { if (cur.moveToFirst()) { int image_id; String image_path; int image_idColumn = cur.getColumnIndex(Thumbnails.IMAGE_ID); int dataColumn = cur.getColumnIndex(Thumbnails.DATA); do { image_id = cur.getInt(image_idColumn); image_path = cur.getString(dataColumn); thumbnailList.put("" + image_id, image_path); } while (cur.moveToNext()); } }
private void getVideoBucket() { // 构造视频缩略图 getVideoThumbnail(); // 添加视频bucket String[] proj = { MediaStore.Video.Thumbnails._ID, MediaStore.Video.Thumbnails.DATA, MediaStore.Video.Media.DURATION, MediaStore.Video.Media.SIZE, MediaStore.Video.Media.DISPLAY_NAME, MediaStore.Video.Media.DATE_MODIFIED }; Cursor mCursor = cr.query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, proj, MediaStore.Video.Media.MIME_TYPE + "=?", new String[] { "video/mp4" }, MediaStore.Video.Media.DATE_MODIFIED + " desc"); if (mCursor != null) { while (mCursor.moveToNext()) { // 获取视频的路径 String videoId = mCursor.getString(mCursor.getColumnIndexOrThrow(MediaStore.Video.Media._ID)); String path = mCursor.getString(mCursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA)); long duration = mCursor.getLong(mCursor.getColumnIndexOrThrow(MediaStore.Video.Media.DURATION)); // 提前生成缩略图,再获取:http://stackoverflow.com/questions/27903264/how-to-get-the-video-thumbnail-path-and-not-the-bitmap MediaStore.Video.Thumbnails.getThumbnail(cr, Long.valueOf(videoId), MediaStore.Video.Thumbnails.MICRO_KIND, null); ImageBucket bucket = bucketList.get("do_Album_Video"); if (bucket == null) { bucket = new ImageBucket(); bucketList.put("do_Album_Video", bucket); bucket.imageList = new ArrayList<ImageItem>(); bucket.bucketName = "Video"; } bucket.count++; ImageItem imageItem = new ImageItem(); imageItem.imageId = videoId; imageItem.imagePath = path; imageItem.thumbnailPath = thumbnailList.get(videoId); imageItem.duration = getFormat(duration); bucket.imageList.add(imageItem); } mCursor.close(); } }
@Override public void bindView(View view, Context context, Cursor cursor) { ((ThumbView)view.findViewById(R.id.picture_item_thumb)) .setImageThumbnail(cursor.getLong(PictureQuery._ID), Thumbnails.MICRO_KIND); ((TextView)view.findViewById(R.id.picture_item_text1)) .setText(cursor.getString(PictureQuery.TITLE)); ((TextView)view.findViewById(R.id.picture_item_text2)) .setText(DateFormat.getDateFormat(view.getContext()) .format(cursor.getLong(PictureQuery.DATE))); }
public void cancel() { super.cancel(false); Thumbnails.cancelThumbnailRequest( getContext().getContentResolver() , mId); }
/** * 得到缩略图 */ private void getThumbnail() { String[] projection = { Thumbnails._ID, Thumbnails.IMAGE_ID, Thumbnails.DATA }; Cursor cursor = cr.query(Thumbnails.EXTERNAL_CONTENT_URI, projection, null, null, null); getThumbnailColumnData(cursor); }
/** * 从数据库中得到缩略图 * * @param cur */ private void getThumbnailColumnData(Cursor cur) { if (cur.moveToFirst()) { int _id; int image_id; String image_path; int _idColumn = cur.getColumnIndex(Thumbnails._ID); int image_idColumn = cur.getColumnIndex(Thumbnails.IMAGE_ID); int dataColumn = cur.getColumnIndex(Thumbnails.DATA); do { // Get the field values _id = cur.getInt(_idColumn); image_id = cur.getInt(image_idColumn); image_path = cur.getString(dataColumn); // Do something with the values. // Log.i(TAG, _id + " image_id:" + image_id + " path:" // + image_path + "---"); // HashMap<String, String> hash = new HashMap<String, String>(); // hash.put("image_id", image_id + ""); // hash.put("path", image_path); // thumbnailList.add(hash); thumbnailList.put("" + image_id, image_path); } while (cur.moveToNext()); } }
/** 创建视频缩略图,返回缩略图文件路径 */ public String createVideoThumbnail(String filePath, String fileName){ Bitmap videoThumb = ThumbnailUtils.createVideoThumbnail(filePath, Thumbnails.MINI_KIND); //关键代码!! return saveBitmap(videoThumb, fileName); //注:saveBitmap方法为保存图片并返回路径的private方法 }
private void getThumbnail() { String[] projection = { Thumbnails._ID, Thumbnails.IMAGE_ID, Thumbnails.DATA }; Cursor cursor = contentResolver.query(Thumbnails.EXTERNAL_CONTENT_URI, projection, null, null, null); getThumbnailColumnData(cursor); }
/** * Retrieves a the bitmap relative to attachment based on mime type */ public static Bitmap getBitmapFromAttachment(Context mContext, Attachment mAttachment, int width, int height) { Bitmap bmp = null; String path; mAttachment.getUri().getPath(); // Video if (Constants.MIME_TYPE_VIDEO.equals(mAttachment.getMime_type())) { // Tries to retrieve full path from ContentResolver if is a new video path = StorageHelper.getRealPathFromURI(mContext, mAttachment.getUri()); // .. or directly from local directory otherwise if (path == null) { path = FileHelper.getPath(mContext, mAttachment.getUri()); } bmp = ThumbnailUtils.createVideoThumbnail(path, Thumbnails.MINI_KIND); if (bmp == null) { return null; } else { bmp = BitmapUtils.createVideoThumbnail(mContext, bmp, width, height); } // Image } else if (Constants.MIME_TYPE_IMAGE.equals(mAttachment.getMime_type()) || Constants.MIME_TYPE_SKETCH.equals(mAttachment.getMime_type())) { try { bmp = BitmapHelper.getThumbnail(mContext, mAttachment.getUri(), width, height); } catch (NullPointerException e) { bmp = null; } // Audio } else if (Constants.MIME_TYPE_AUDIO.equals(mAttachment.getMime_type())) { bmp = ThumbnailUtils.extractThumbnail( decodeSampledBitmapFromResourceMemOpt(mContext.getResources().openRawResource(R.drawable.play), width, height), width, height); // File } else if (Constants.MIME_TYPE_FILES.equals(mAttachment.getMime_type())) { // vCard if (Constants.MIME_TYPE_CONTACT_EXT.equals(FilenameUtils.getExtension(mAttachment.getName()))) { bmp = ThumbnailUtils.extractThumbnail( decodeSampledBitmapFromResourceMemOpt(mContext.getResources().openRawResource(R.drawable.vcard), width, height), width, height); } else { bmp = ThumbnailUtils.extractThumbnail( decodeSampledBitmapFromResourceMemOpt(mContext.getResources().openRawResource(R.drawable.files), width, height), width, height); } } return bmp; }
/** * 获取MPO文件的预设打下的缩略图 * @param filePath * @param thumbSize * @return */ static public Bitmap[] getThumbnails(String filePath, int thumbSize){//× switch (thumbSize) { case Thumbnails.FULL_SCREEN_KIND: break; case Thumbnails.MINI_KIND: break; case Thumbnails.MICRO_KIND: break; default: break; } return null; }
@Override protected Bitmap doInBackground(Void... params) { return Thumbnails.getThumbnail(getContext().getContentResolver(), mId, mKind, null); }