`
thunder_yan
  • 浏览: 109082 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

解决Bitmap读取频发OOM

阅读更多
/**
 * Bitmap 工具包
 * @author Thunder
 * @version 
 * @2012-8-24
 */
public class BitmapUtil {
	
	private static BitmapFactory.Options mOptions = null;
	
	static {
		mOptions = new BitmapFactory.Options();
		
		mOptions.inJustDecodeBounds = false;
        // options.inSampleSize = 10;   //width,hight设为原来的十分一
		mOptions.inPreferredConfig = Bitmap.Config.RGB_565; // 这里也可以是ARGB_8888
		mOptions.inPurgeable = true;
		mOptions.inInputShareable = true;
	}

	/**
	 * 获取Bitmap
	 * @param assetManager
	 * @param src
	 * @return
	 */
	public static Bitmap getBitmap(AssetManager assetManager, String src) {
		
		Bitmap temp = null;
		
        try {
			temp = BitmapFactory.decodeStream(assetManager.open(src), null, mOptions);
		} catch (IOException e) {
			e.printStackTrace();
			return temp;
		}
        
        return temp;
	}
	
 

 

分享到:
评论
1 楼 119568242 2012-09-13  

相关推荐

Global site tag (gtag.js) - Google Analytics