}
mRecycled = true;
}
}
isRecycled()
判断位图内存是否已经被回收。
checkRecycled
如果已经被回收,则抛出非法状态异常IllegalStateException。
/**
-
This is called by methods that want to throw an exception if the bitmap
-
has already been recycled.
*/
private void checkRecycled(String errorMessage) {
if (mRecycled) {
throw new IllegalStateException(errorMessage);
}
}
getWidth() 获取宽度
getHeight() 获取高度
getScaledWidth(Canvas canvas)
获取经指定密度转换后的宽度
/**
-
Convenience for calling {@link #getScaledWidth(int)} with the target
-
density of the given {@link Canvas}.
*/
public int getScaledWidth(Canvas canvas) {
return scaleFromDensity(getWidth(), mDensity, canvas.mDensity);
}
/**
-
Convenience for calling {@link #getScaledWidth(int)} with the target
-
density of the given {@link DisplayMetrics}.
*/
public int getScaledWidth(DisplayMetrics metrics) {
return scaleFromDensity(getWidth(), mDensity, metrics.densityDpi);
}
/**
- @hide
*/
static public int scaleFromDensity(int size, int sdensity, int tdensity) {
if (sdensity == DENSITY_NONE || tdensity == DENSITY_NONE || sdensity == tdensity) {
return size;
}
// Scale by tdensity / sdensity, rounding up.
return ((size * tdensity) + (sdensity >> 1)) / sdensity;
}
getScaledHeight(Canvas canvas)
获取经制定密度转换后的高度
/**
-
Convenience for calling {@link #getScaledHeight(int)} with the target
-
density of the given {@link Canvas}.
*/
public int getScaledHeight(Canvas canvas) {
return scaleFromDensity(getHeight(), mDensity, canvas.mDensity);
}
/**
-
Convenience for calling {@link #getScaledHeight(int)} with the target
-
density of the given {@link DisplayMetrics}.
*/
public int getScaledHeight(DisplayMetrics metrics) {
return scaleFromDensity(getHeight(), mDensity, metrics.densityDpi);
}
getRowBytes()
获取native位图行像素的byte数
/**
-
Return the number of bytes between rows in the bitmap’s pixels. Note that
-
this refers to the pixels as stored natively by the bitmap. If you call
-
getPixels() or setPixels(), then the pixels are uniformly treated as
-
32bit values, packed according to the Color class.
-
As of {@link android.os.Build.VERSION_CODES#KITKAT}, this method
-
should not be used to calculate the memory usage of the bitmap. Instead,
-
see {@link #getAllocationByteCount()}.
-
@return number of bytes between rows of the native bitmap pixels.
*/
public final int getRowBytes() {
if (mRecycled) {
Log.w(TAG, “Called getRowBytes() on a recycle()'d bitmap! This is undefined behavior!”);
}
return nativeRowBytes(mNativePtr);
}
getByteCount()
获取可以存储此bitmap像素的最小字节。返回行像素x高度。
/**
-
Returns the minimum number of bytes that can be used to store this bitmap’s pixels.
-
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() {
// int result permits bitmaps up to 46,340 x 46,340
return getRowBytes() * getHeight();
}
getAllocationByteCount()
获取用来存储bitmap所分配的内存大小。在bitmap的生命周期内此值不会改变。
/**
-
Returns the size of the allocated memory used to store this bitmap’s pixels.
-
This can be larger than the result of {@link #getByteCount()} if a bitmap is reused to
-
decode other bitmaps of smaller size, or by manual reconfiguration. See {@link
-
#reconfigure(int, int, Config)}, {@link #setWidth(int)}, {@link #setHeight(int)}, {@link
-
#setConfig(Bitmap.Config)}, and {@link BitmapF