因此,我有一張圖像的Uri,用戶從他的SD卡中選擇了圖像。我想顯示該圖像的縮略圖,因爲很明顯,圖像可能很大並佔據整個屏幕。任何人都知道嗎?Android:獲取SD卡上的圖像的縮略圖,給出原始圖像的Uri
11
A
回答
5
此代碼將做的工作:
Bitmap getPreview(URI uri) {
File image = new File(uri);
BitmapFactory.Options bounds = new BitmapFactory.Options();
bounds.inJustDecodeBounds = true;
BitmapFactory.decodeFile(image.getPath(), bounds);
if ((bounds.outWidth == -1) || (bounds.outHeight == -1))
return null;
int originalSize = (bounds.outHeight > bounds.outWidth) ? bounds.outHeight
: bounds.outWidth;
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inSampleSize = originalSize/THUMBNAIL_SIZE;
return BitmapFactory.decodeFile(image.getPath(), opts);
}
您可能要計算的2最近的電源用於inSampleSize
,因爲it's said要快。
2
我相信這段代碼生成縮略圖從文件SD卡上的最快的方法:
public static Bitmap decodeFile(String file, int size) {
//Decode image size
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeFile(file, o);
//Find the correct scale value. It should be the power of 2.
int width_tmp = o.outWidth, height_tmp = o.outHeight;
int scale = (int)Maths.pow(2, (double)(scale-1));
while (true) {
if (width_tmp/2 < size || height_tmp/2 < size) {
break;
}
width_tmp /= 2;
height_tmp /= 2;
scale++;
}
//Decode with inSampleSize
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize = scale;
return BitmapFactory.decodeFile(file, o2);
}
9
您可以在API使用ThumnailUtil級Java的
Bitmap resized = ThumbnailUtils.extractThumbnail(BitmapFactory.decodeFile(file.getPath()), width, height);
public static Bitmap createVideoThumbnail (String filePath, int kind)
新增簡單地創建縮略圖視頻和圖像級別8 爲視頻創建視頻縮略圖。如果視頻損壞或格式不被支持,可能會返回null。
參數 文件路徑視頻文件的路徑 那種可以MINI_KIND或MICRO_KIND
0
一些嘗試我無法從SD獲取圖像的縮略圖路徑。 我解決了這個問題,得到一個android圖像位圖,然後在適配器中爲gridview創建圖像視圖(或者你需要的地方)。因此,我調用方法imageView.setImageBitmap(someMethod(Context context, imageID))
Bitmap someMethod(Context context, long imageId){
Bitmap bitmap = Media.Images.Thumbnails.getThumbnail(context.getAplicationContext.getContentResolver(), imageid, MediaStore.Images.Thumbnails.MINI_KIND, null);
return bitmap;
}
您可以使用本指南(Get list of photo galleries on Android)
0
如果你喜歡HQ縮略圖從SD卡獲取圖像ID,所以用[RapidDecoder] [1]庫。這是簡單如下:
import rapid.decoder.BitmapDecoder;
...
Bitmap bitmap = BitmapDecoder.from(getResources(), R.drawable.image)
.scale(width, height)
.useBuiltInDecoder(true)
.decode();
不要忘了,如果你想縮小小於50%和HQ結果使用內置的解碼器。 我在API等級8中測試過它:)
相關問題
- 1. android載入SD卡中圖像的縮略圖
- 2. 如何獲取存儲在SD卡上的圖像的Uri?
- 3. 通過Android中的縮略圖ID的圖像的原始ID
- 4. Android:從SD卡上的特定位置獲取縮略圖
- 5. 從SD卡中獲取圖像 - android
- 6. 從SD卡讀取圖像的android
- 7. 保存縮放圖像SD卡android
- 8. Tridion 2009 SP1:圖像縮略圖 - 如何發佈原始圖像?
- 9. 從SD卡中取出圖像,壓縮並保存回SD?
- 10. Android:如何從SD卡上傳圖像
- 11. 從Gopro SD卡獲取圖像Objective-c
- 12. 使用ContentResolver和Cursor獲取Android中圖像的縮略圖
- 13. 如何從android中的SD卡獲取指定的圖像?
- 14. 如何從存儲在SD卡上的圖像獲取圖像路徑
- 15. 從Android的SD卡刪除圖像
- 16. Android的圖像保存到SD卡
- 17. 圖像縮略圖
- 18. android,刷新圖像縮略圖或sd卡在調用意圖選擇圖像之前
- 19. 我如何獲得縮略圖的原始圖像instread的SRC jQuery中
- 20. Javascript獲取圖像的原始碼
- 21. 如何刪除存儲在sd卡上的位圖圖像android
- 22. 如何從android中的SD卡獲取圖像?
- 23. 如何從SD卡上的CoverFlow圖像
- 24. 原始圖片的縮略圖
- 25. 如何將從SD卡加載的圖像縮放到圖像視圖?
- 26. 獲取SD卡上所有圖像的數組列表
- 27. 獲取從圖庫中選擇的圖像的路徑(在SD卡上)
- 28. 列出圖像縮略圖在android中的圖像名稱和大小
- 29. 在列表視圖中顯示圖像的縮略圖(出現在SD卡中的不同位置)
- 30. Android:從圖像獲取縮略圖信息
什麼是THUMBNAIL SIZE – 2013-10-17 04:35:56
構造函數File(Uri)未定義 – hasanghaforian 2015-04-22 16:49:40