[英]How to handle large amount of pictures. which thumbnails sould be shown in android app?
我的Android應用程序有問題。 我使用的應用程序使用手機/平板電腦的內置攝像頭拍攝照片。由於攝像頭的高分辨率,這些照片有時尺寸很大。
現在,我加載該應用程序並創建一個listView,其中圖片的小縮略圖在左側,右側是一些文本。
我以這種方式創建圖片:
Bitmap a = BitmapFactory.decodeFile(url);
int width = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
(float) 66.0, context.getResources().getDisplayMetrics());
int height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
(float) 48.0, context.getResources().getDisplayMetrics());
Bitmap b = Bitmap.createScaledBitmap(a, width, height, false);
問題在於此步驟需要相當長的時間。
有什么辦法可以使速度更快?
沒有辦法使其更快,但您不應阻塞UI線程。 看到
這是我在這里使用的解決方案: https : //stackoverflow.com/a/5934983/1369222
效果很好!
byte[] imageData = null;
try
{
final int THUMBNAIL_SIZE = 64;
FileInputStream fis = new FileInputStream(fileName);
Bitmap imageBitmap = BitmapFactory.decodeStream(fis);
imageBitmap = Bitmap.createScaledBitmap(imageBitmap, THUMBNAIL_SIZE, THUMBNAIL_SIZE, false);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
imageBitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
imageData = baos.toByteArray();
}
catch(Exception ex) {
}
確保在異步或獨立線程任務中執行此操作,以免阻塞UI線程!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.