android高效读取大图片 防止OOM

工具方法

public static Bitmap getImageFromAssetsFile1(Context context, String fileName) {
		Bitmap image = null;
		 ByteArrayOutputStream outputStream=new ByteArrayOutputStream();
			byte[] bytes = new byte[1024];//读取
		    int len=0;
			AssetManager am = context.getResources().getAssets();
			try {
				InputStream is = am.open(fileName);
				while((len=is.read(bytes))!=-1){
					outputStream.write(bytes, 0, len);//写入
				}
				byte[] result=outputStream.toByteArray();//声明字节数组
				image = BitmapFactory.decodeByteArray(result, 0, result. length);
			} catch (IOException e) { 
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		return image;
	}


你可能感兴趣的:(android)