-
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 BitmapFactory.Options#inBitmap
-
BitmapFactory.Options.inBitmap}. If a bitmap is not modified in this way, this value will be
-
the same as that returned by {@link #getByteCount()}.
-
This value will not change over the lifetime of a Bitmap.
-
@see #reconfigure(int, int, Config)
*/
public final int getAllocationByteCount() {
if (mBuffer == null) {
// native backed bitmaps don’t support reconfiguration,
// so alloc size is always content size
return getByteCount();
}
return mBuffer.length;
}
getConfig()
获取Config枚举:
-
ALPHA_8, 代表8位Alpha位图,每个像素占用1byte内存
-
RGB_565,代表8位RGB位图,每个像素占用2byte内存
-
ARGB_4444 (@deprecated),代表16位ARGB位图,每个像素占用2byte内存
-
ARGB_8888,代表32位ARGB位图,每个像素占用4byte内存
/**
-
If the bitmap’s internal config is in one of the public formats, return
-
that config, otherwise return null.
*/
public final Config getConfig() {
if (mRecycled) {
Log.w(TAG, “Called getConfig() on a recycle()'d bitmap! This is undefined behavior!”);
}
return Config.nativeToConfig(nativeConfig(mNativePtr));
}
hasAlpha()
检测bitmap是否支持像素级别透明。
/** Returns true if the bitmap’s config supports per-pixel alpha, and
-
if the pixels may contain non-opaque alpha values. For some configs,