Android最省的方式读取资源图片

Home / Android MrLee 2014-12-17 3981

	/**
	 * 以最省的方式读取本地图片
	 * @param context Context
	 * @param resId 图片id
	 * @return Bitmap 图像格式
	 */
	public Bitmap readBitmap(Context context, int resId) {
		BitmapFactory.Options options = new BitmapFactory.Options();
		options.inPreferredConfig = Bitmap.Config.RGB_565;
		options.inPurgeable = true;
		options.inInputShareable = true;
		InputStream is = context.getResources().openRawResource(resId);
		Bitmap bitmap = BitmapFactory.decodeStream(is, null, options);
		try {
			is.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return bitmap;
	}

本文链接:https://www.it72.com/441.htm

推荐阅读
最新回复 (1)
返回