---
title: "获取Bitmap大小"
author: "wangleyiang"
date: "2013-10-08T17:59:01Z"
tags: ["bitmap", "option"]
categories: ["移动开发"]
slug: "bitmap"
draft: false
lastmod: "2013-10-08T17:59:01Z"
id: 1953380
url: "https://wangleyiang.iteye.com/blog/1953380"
---

Bitmap的操作常常会导致OOM（内存溢出）。

在处理Bitmap时，可以通过先获取Bitmap的边框来确定缩放处理。

具体操作可以通过BitmapFactory.Option来实现，具体步骤如下：

1. 设置inJustDecodeBounds为true，获取option；
2. 根据option计算inSampleSize；
3. 解码Bitmap前要设置inJustDecodeBounds为false；