实例化对象
Bitmap对象大小和像素大小
BitmapFactory.Options
如何实例化对象
Bitmap文档
Bitmap提供了一系列的createXX方法,可以通过:Bitmap、DisplayMetrics、Picture、RGB的颜色数组等得到一个Bitmap对象。
BitmapFactory提供了一系列的decodeXX方法。流行、文件、资源等得到一个Bitmap对象。
示例:
bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.car);
...
bitmap = Bitmap.createBitmap(BitmapFactory.decodeResource(getResources(),R.drawable.car));
一般通过Bitmap创建的话需要先事先有一个Bitmap对象,或者通过自己指定一些像素属性。
BitmapFactory基本用语将一个图片资源变为解码成Bitmap对象。
Bitmap对象大小和像素大小。
/**
* 返回Bitmap对象像素所占内存大小
*
*
As of {@link android.os.Build.VERSION_CODES#KITKAT}, the result of this method can
* no longer be used to determine memory usage of a bitmap. See {@link
* #getAllocationByteCount()}.
*/
public final int getByteCount() {
if (mRecycled) {
Log.w(TAG, "Called getByteCount() on a recycle()'d bitmap! "
+ "This is undefined behavior!");
return 0;
}
// int result permits bitmaps up to 46,340 x 46,340
return getRowBytes() * getHeight();
}
此方法在19之后就不能在用于定位Bitmap对象内存使用的情况,需要用getAllocationByteCount
/**
* Returns the size of the allocated memory used to store this bitmap's pi