/*
顯示長(zhǎng)圖片,但是要小心OOM,目前我的圖片為5.32MB可以正常使用.
如果出現(xiàn)OOM,可以嘗試使用ListView
也可以使用webView,但是webView體驗(yàn)不如本地原生.
*/
public void setLongPicture(String assetsLocation){
try {
//獲得圖片的寬、高
? ? ? ? BitmapFactory.Options tmpOptions =new BitmapFactory.Options();
? ? ? ? tmpOptions.inJustDecodeBounds =true;
? ? ? ? BitmapFactory.decodeStream(getAssets().open(assetsLocation), null, tmpOptions);
? ? ? ? int width =tmpOptions.outWidth;
? ? ? ? int height =tmpOptions.outHeight;
? ? ? ? //設(shè)置顯示圖片的中心區(qū)域
? ? ? ? BitmapRegionDecoder bitmapRegionDecoder =BitmapRegionDecoder.newInstance(getAssets().open(assetsLocation), false);
? ? ? ? BitmapFactory.Options options =new BitmapFactory.Options();
? ? ? ? options.inPreferredConfig =Bitmap.Config.ARGB_8888;
? ? ? ? int beforeHeight;
? ? ? ? int currentHeight =0;
? ? ? ? int singleIncrease =4096;
? ? ? ? Bitmap bitmap;
? ? ? ? ImageView imageView;
? ? ? ? while (true){
beforeHeight =currentHeight;
? ? ? ? ? ? currentHeight+=singleIncrease;
? ? ? ? ? ? if (currentHeight
bitmap =bitmapRegionDecoder.decodeRegion(new Rect(0, beforeHeight, width, currentHeight), options);
? ? ? ? ? ? ? ? imageView =new ImageView(this);
? ? ? ? ? ? ? ? imageView.setImageBitmap(bitmap);
? ? ? ? ? ? ? ? mLl.addView(imageView);
? ? ? ? ? ? }else{
bitmap =bitmapRegionDecoder.decodeRegion(new Rect(0, beforeHeight, width, height), options);
? ? ? ? ? ? ? ? imageView =new ImageView(this);
? ? ? ? ? ? ? ? imageView.setImageBitmap(bitmap);
? ? ? ? ? ? ? ? mLl.addView(imageView);
? ? ? ? ? ? ? ? return;
? ? ? ? ? ? }
}
}catch (IOException e) {
e.printStackTrace();
? ? }
}