聊天平台源码,通过MediaStore获取缩略图模糊
聊天平台源码,通过MediaStore获取缩略图模糊实现的方法
获取缩略图的方法
Bitmap thumbnail = Images.Thumbnails.getThumbnail(mContext.getContentResolver(), id, Images.Thumbnails.MICRO_KIND, null)
该方法为系统方法getThumbnail
/**
* Return thumbnail representing a specific image item. If a
* thumbnail doesn't exist, this method will block until it's
* generated. Callers are responsible for their own in-memory
* caching of returned values.
*
* As of {@link android.os.Build.VERSION_CODES#Q}, this output
* of the thumbnail has correct rotation, don't need to rotate
* it again.
*
* @param imageId the image item to obtain a thumbnail for.
* @param kind optimal thumbnail size desired.
* @return decoded thumbnail, or {@code null} if problem was
* encountered.
* @deprecated Callers should migrate to using
* {@link ContentResolver#loadThumbnail}, since it
* offers richer control over requested thumbnail sizes
* and cancellation behavior.
*/
@Deprecated
public static Bitmap getThumbnail(ContentResolver cr, long imageId, int kind,
BitmapFactory.Options options) {
final Uri uri = ContentUris.withAppendedId(
Images.Media.EXTERNAL_CONTENT_URI, imageId);
return InternalThumbnails.getThumbnail(cr, uri, kind, options);
}
观察到参数@param kind optimal thumbnail size desired
packages/providers/MediaProvider/apex/framework/java/android/provider/MediaStore.java
public static class ThumbnailConstants {
public static final int MINI_KIND = 1;
public static final int FULL_SCREEN_KIND = 2;
public static final int MICRO_KIND = 3;
public static final Size MINI_SIZE = new Size(512, 384);
public static final Size FULL_SCREEN_SIZE = new Size(1024, 786);
public static final Size MICRO_SIZE = new Size(96, 96);
public static @NonNull Size getKindSize(int kind) {
if (kind == ThumbnailConstants.MICRO_KIND) {
return ThumbnailConstants.MICRO_SIZE;
} else if (kind == ThumbnailConstants.FULL_SCREEN_KIND) {
return ThumbnailConstants.FULL_SCREEN_SIZE;
} else if (kind == ThumbnailConstants.MINI_KIND) {
return ThumbnailConstants.MINI_SIZE;
} else {
throw new IllegalArgumentException("Unsupported kind: " +
}
}
}
因此,如要修改缩略图清晰度,可以修改第三个参数为MINI_KIND或FULL_SCREEN_KIND即可。
以上就是聊天平台源码,通过MediaStore获取缩略图模糊实现的方法, 更多内容欢迎关注之后的文章