本文整理了Java中android.graphics.Bitmap.getAllocationByteCount()
方法的一些代码示例,展示了Bitmap.getAllocationByteCount()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bitmap.getAllocationByteCount()
方法的具体详情如下:
包路径:android.graphics.Bitmap
类名称:Bitmap
方法名:getAllocationByteCount
暂无
代码示例来源:origin: bumptech/glide
@Nullable
@TargetApi(Build.VERSION_CODES.KITKAT)
private static String getBitmapString(Bitmap bitmap) {
if (bitmap == null) {
return null;
}
String sizeString = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT
? " (" + bitmap.getAllocationByteCount() + ")" : "";
return "[" + bitmap.getWidth() + "x" + bitmap.getHeight() + "] " + bitmap.getConfig()
+ sizeString;
}
代码示例来源:origin: bumptech/glide
/**
* Returns the in memory size of the given {@link Bitmap} in bytes.
*/
@TargetApi(Build.VERSION_CODES.KITKAT)
public static int getBitmapByteSize(@NonNull Bitmap bitmap) {
// The return value of getAllocationByteCount silently changes for recycled bitmaps from the
// internal buffer size to row bytes * height. To avoid random inconsistencies in caches, we
// instead assert here.
if (bitmap.isRecycled()) {
throw new IllegalStateException("Cannot obtain size for recycled Bitmap: " + bitmap
+ "[" + bitmap.getWidth() + "x" + bitmap.getHeight() + "] " + bitmap.getConfig());
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
// Workaround for KitKat initial release NPE in Bitmap, fixed in MR1. See issue #148.
try {
return bitmap.getAllocationByteCount();
} catch (@SuppressWarnings("PMD.AvoidCatchingNPE") NullPointerException e) {
// Do nothing.
}
}
return bitmap.getHeight() * bitmap.getRowBytes();
}
代码示例来源:origin: commonsguy/cw-omnibus
@TargetApi(Build.VERSION_CODES.KITKAT)
private int byteCount(Bitmap b) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
return(b.getAllocationByteCount());
}
return(b.getByteCount());
}
}
代码示例来源:origin: square/assertj-android
@TargetApi(KITKAT)
public BitmapAssert hasAllocationByteCount(int count) {
isNotNull();
int actualCount = actual.getAllocationByteCount();
assertThat(actualCount) //
.overridingErrorMessage("Expected allocation byte count <%s> but was <%s>.", count,
actualCount) //
.isEqualTo(count);
return this;
}
代码示例来源:origin: stackoverflow.com
/**
* returns the bytesize of the give bitmap
*/
public static int byteSizeOf(Bitmap bitmap) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
return bitmap.getAllocationByteCount();
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
return bitmap.getByteCount();
} else {
return bitmap.getRowBytes() * bitmap.getHeight();
}
}
代码示例来源:origin: koral--/android-gif-drawable
/**
* Returns size of the memory needed to store pixels of this object. It counts possible length of all frame buffers.
* Returned value may be lower than amount of actually allocated memory if GIF uses dispose to previous method but frame requiring it
* has never been needed yet. Returned value does not change during runtime.
*
* @return possible size of the memory needed to store pixels of this object
*/
public long getAllocationByteCount() {
long byteCount = mNativeInfoHandle.getAllocationByteCount();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
byteCount += mBuffer.getAllocationByteCount();
} else {
byteCount += getFrameByteCount();
}
return byteCount;
}
代码示例来源:origin: koral--/android-gif-drawable
/**
* Like {@link #getAllocationByteCount()} but includes also backing {@link android.graphics.Bitmap} and takes sample size into account.
*
* @param oldDrawable optional old drawable to be reused, pass {@code null} if there is no one
* @param sampleSize sample size, pass {@code 1} if not using subsampling
* @return possible size of the memory needed to store pixels
* @throws IllegalArgumentException if sample size out of range
*/
@Beta
public long getDrawableAllocationByteCount(@Nullable GifDrawable oldDrawable, @IntRange(from = 1, to = Character.MAX_VALUE) int sampleSize) {
if (sampleSize < 1 || sampleSize > Character.MAX_VALUE) {
throw new IllegalStateException("Sample size " + sampleSize + " out of range <1, " + Character.MAX_VALUE + ">");
}
final int sampleSizeFactor = sampleSize * sampleSize;
final long bufferSize;
if (oldDrawable != null && !oldDrawable.mBuffer.isRecycled()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
bufferSize = oldDrawable.mBuffer.getAllocationByteCount();
} else {
bufferSize = oldDrawable.getFrameByteCount();
}
} else {
bufferSize = (mWidth * mHeight * 4) / sampleSizeFactor;
}
return (mPixelsBytesCount / sampleSizeFactor) + bufferSize;
}
代码示例来源:origin: robolectric/robolectric
@Test
@Config(minSdk = KITKAT)
public void getAllocationByteCount() {
Bitmap bitmap = Bitmap.createBitmap(100, 200, Bitmap.Config.ARGB_8888);
assertThat(bitmap.getAllocationByteCount()).isGreaterThan(0);
}
代码示例来源:origin: bumptech/glide
@Test
public void loadWideGamutImage_withArgb888OfSufficientSizeInPool_usesArgb8888Bitmap() {
Bitmap wideGamut = Bitmap.createBitmap(100, 50, Bitmap.Config.RGBA_F16);
byte[] data = asPng(wideGamut);
Bitmap argb8888 = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
Glide.init(context, new GlideBuilder()
.setBitmapPool(new LruBitmapPool(wideGamut.getAllocationByteCount() * 5)));
Glide.get(context).getBitmapPool().put(argb8888);
Bitmap result =
concurrency.get(
Glide.with(context)
.asBitmap()
.load(data)
.submit());
assertThat(result).isSameAs(argb8888);
}
代码示例来源:origin: moagrius/TileView
private static boolean qualifies(Bitmap candidate, BitmapFactory.Options targetOptions) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
int width = targetOptions.outWidth / targetOptions.inSampleSize;
int height = targetOptions.outHeight / targetOptions.inSampleSize;
int byteCount = width * height * getBytesPerPixel(candidate.getConfig());
return byteCount <= candidate.getAllocationByteCount();
}
return candidate.getWidth() == targetOptions.outWidth
&& candidate.getHeight() == targetOptions.outHeight
&& targetOptions.inSampleSize == 1;
}
代码示例来源:origin: guolindev/giffun
/**
* Returns the in memory size of the given {@link Bitmap} in bytes.
*/
@TargetApi(Build.VERSION_CODES.KITKAT)
public static int getBitmapByteSize(Bitmap bitmap) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
// Workaround for KitKat initial release NPE in Bitmap, fixed in MR1. See issue #148.
try {
return bitmap.getAllocationByteCount();
} catch (NullPointerException e) {
// Do nothing.
}
}
return bitmap.getHeight() * bitmap.getRowBytes();
}
代码示例来源:origin: mozilla-tw/Rocket
@Nullable
@TargetApi(Build.VERSION_CODES.KITKAT)
private static String getBitmapString(Bitmap bitmap) {
if (bitmap == null) {
return null;
}
String sizeString = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT
? " (" + bitmap.getAllocationByteCount() + ")" : "";
return "[" + bitmap.getWidth() + "x" + bitmap.getHeight() + "] " + bitmap.getConfig()
+ sizeString;
}
代码示例来源:origin: yangchong211/YCAudioPlayer
@Override
protected int sizeOf(String key, Bitmap bitmap) {
//API19
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
return bitmap.getAllocationByteCount() / 1024;
} else {
return bitmap.getByteCount() / 1024;
}
}
};
代码示例来源:origin: hidaron/HiFrameAnimation
private static int getBitmapByteCount(Bitmap bitmap) {
if (null == bitmap) return 0;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
return bitmap.getAllocationByteCount();
}
return bitmap.getByteCount();
}
代码示例来源:origin: com.squareup.assertj/assertj-android
@TargetApi(KITKAT)
public BitmapAssert hasAllocationByteCount(int count) {
isNotNull();
int actualCount = actual.getAllocationByteCount();
assertThat(actualCount) //
.overridingErrorMessage("Expected allocation byte count <%s> but was <%s>.", count,
actualCount) //
.isEqualTo(count);
return this;
}
代码示例来源:origin: jruesga/rview
@TargetApi(Build.VERSION_CODES.KITKAT)
public static int byteSizeOf(Bitmap bitmap) {
if (AndroidHelper.isKitkatOrGreater()) {
return bitmap.getAllocationByteCount();
}
return bitmap.getByteCount();
}
}
代码示例来源:origin: stackoverflow.com
public static int getBitmapByteCount(Bitmap bitmap) {
if (VERSION.SDK_INT < VERSION_CODES.HONEYCOMB_MR1)
return bitmap.getRowBytes() * bitmap.getHeight();
if (VERSION.SDK_INT < VERSION_CODES.KITKAT)
return bitmap.getByteCount();
return bitmap.getAllocationByteCount();
}
代码示例来源:origin: qyxxjd/AndroidBasicProject
/**
* 得到bitmap的大小
*/
public static int getBitmapSize(Bitmap bitmap) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { //API 19
return bitmap.getAllocationByteCount();
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {//API 12
return bitmap.getByteCount();
}
// 在低版本中用一行的字节x高度
return bitmap.getRowBytes() * bitmap.getHeight(); //earlier version
}
代码示例来源:origin: luhaoaimama1/zone-sdk
/**
* 得到bitmap的大小
*/
public static int getBitmapSize(Bitmap bitmap) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { //API 19
return bitmap.getAllocationByteCount();
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {//API 12
return bitmap.getByteCount();
}
// 在低版本中用一行的字节x高度
return bitmap.getRowBytes() * bitmap.getHeight(); //earlier version
}
代码示例来源:origin: stackoverflow.com
int bytes = byteSizeOf(b);
protected int byteSizeOf(Bitmap data) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR1) {
return data.getRowBytes() * data.getHeight();
} else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
return data.getByteCount();
} else {
return data.getAllocationByteCount();
}
内容来源于网络,如有侵权,请联系作者删除!