Java Code Examples for android.graphics.Bitmap.getRowBytes()

The following are Jave code examples for showing how to use getRowBytes() of the android.graphics.Bitmap class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Android-Practice   File: ImageCache.java   View Source Code Vote up 6 votes
/**
 * Get the size in bytes of a bitmap in a BitmapDrawable. Note that from Android 4.4 (KitKat)
 * onward this returns the allocated memory size of the bitmap which can be larger than the
 * actual bitmap data byte count (in the case it was re-used).
 *
 * @param value
 * @return size in bytes
 */
@TargetApi(VERSION_CODES.KITKAT)
public static int getBitmapSize(BitmapDrawable value) {
    Bitmap bitmap = value.getBitmap();

    // From KitKat onward use getAllocationByteCount() as allocated bytes can potentially be
    // larger than bitmap byte count.
    if (Utils.hasKitKat()) {
        return bitmap.getAllocationByteCount();
    }

    if (Utils.hasHoneycombMR1()) {
        return bitmap.getByteCount();
    }

    // Pre HC-MR1
    return bitmap.getRowBytes() * bitmap.getHeight();
}
 
Example 2
Project: GitHub   File: Util.java   View Source Code Vote up 6 votes
/**
 * Returns the in memory size of the given {@link Bitmap} in bytes.
 */
@TargetApi(Build.VERSION_CODES.KITKAT)
public static int getBitmapByteSize(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 (NullPointerException e) {
      // Do nothing.
    }
  }
  return bitmap.getHeight() * bitmap.getRowBytes();
}
 
Example 3
Project: GitHub   File: BitmapPrepareProducer.java   View Source Code Vote up 5 votes
private void internalPrepareBitmap(CloseableReference<CloseableImage> newResult) {
  if (newResult == null || !newResult.isValid()) {
    return;
  }

  final CloseableImage closeableImage = newResult.get();
  if (closeableImage == null || closeableImage.isClosed()) {
    return;
  }

  if (closeableImage instanceof CloseableStaticBitmap) {
    final CloseableStaticBitmap staticBitmap = (CloseableStaticBitmap) closeableImage;
    final Bitmap bitmap = staticBitmap.getUnderlyingBitmap();
    if (bitmap == null) {
      return;
    }

    final int bitmapByteCount = bitmap.getRowBytes() * bitmap.getHeight();
    if (bitmapByteCount < mMinBitmapSizeBytes) {
      return;
    }
    if (bitmapByteCount > mMaxBitmapSizeBytes) {
      return;
    }

    bitmap.prepareToDraw();
  }
}
 
Example 4
Project: Accessibility   File: BitmapUtils.java   View Source Code Vote up 5 votes
public static int getBitmapSize(Bitmap bitmap){
    if(bitmap != null){
        try{
            if(Build.VERSION.SDK_INT >= AndroidVersionCodes.KITKAT){
                return bitmap.getAllocationByteCount();
            }else if(Build.VERSION.SDK_INT >= AndroidVersionCodes.HONEYCOMB_MR1){
                return bitmap.getByteCount();
            }else{
                return bitmap.getRowBytes() * bitmap.getHeight();
            }
        }catch (Exception e){
        }
    }
    return 0;
}
 
Example 5
Project: yyox   File: PictureUtil.java   View Source Code Vote up 5 votes
/**
 * 得到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
}
 
Example 6
Project: DailyStudy   File: BitmapUtil.java   View Source Code Vote up 5 votes
public static LruCache lruCache() {
        int maxMemory = (int) Runtime.getRuntime().maxMemory();
        int cacheSize = maxMemory / 8;
        LruCache<String, Bitmap> cache = new LruCache<String, Bitmap>(cacheSize) {
            @Override
            protected int sizeOf(String key, Bitmap value) {
                return value.getRowBytes() * value.getHeight() / 1024;
            }
        };
//        cache.put()
//        cache.remove()
//        cache.get()
        return cache;
    }
 
Example 7
Project: boohee_v5.6   File: LruMemoryCache.java   View Source Code Vote up 4 votes
private int sizeOf(String key, Bitmap value) {
    return value.getRowBytes() * value.getHeight();
}
 
Example 8
Project: omnicrow-android   File: BitmapLruCache.java   View Source Code Vote up 4 votes
@Override
protected int sizeOf(String key, Bitmap value) {
    return value.getRowBytes() * value.getHeight();
}
 
Example 9
Project: GitHub   File: LRULimitedMemoryCache.java   View Source Code Vote up 4 votes
@Override
protected int getSize(Bitmap value) {
	return value.getRowBytes() * value.getHeight();
}
 
Example 10
Project: Sega   File: MemoryCache.java   View Source Code Vote up 4 votes
private long getSizeInBytes(Bitmap bitmap) {
    if(bitmap==null)
        return 0;
    return bitmap.getRowBytes() * bitmap.getHeight();
}
 
Example 11
Project: letv   File: LRULimitedMemoryCache.java   View Source Code Vote up 4 votes
protected int getSize(Bitmap value) {
    return value.getRowBytes() * value.getHeight();
}
 
Example 12
Project: health   File: MemoryCache.java   View Source Code Vote up 4 votes
long getSizeInBytes(Bitmap bitmap) {
    if(bitmap==null)
        return 0;
    return bitmap.getRowBytes() * bitmap.getHeight();
}
 
Example 13
Project: android-project-gallery   File: FIFOLimitedMemoryCache.java   View Source Code Vote up 4 votes
@Override
protected int getSize(Bitmap value) {
	return value.getRowBytes() * value.getHeight();
}
 
Example 14
Project: BlogBookApp   File: LruBitmapCache.java   View Source Code Vote up 4 votes
@Override
protected int sizeOf(String key, Bitmap value) {
    return value.getRowBytes() * value.getHeight() / 1024;
}
 
Example 15
Project: FreeStreams-TVLauncher   File: CacheUtils.java   View Source Code Vote up 4 votes
/**
 * 获得bitmap的字节大小.
 */
public static int getBitmapSize(Bitmap bitmap)
{
    return bitmap.getRowBytes() * bitmap.getHeight();
}
 
Example 16
Project: ImageLoaderProcessor   File: LruCacheUtils.java   View Source Code Vote up 4 votes
@Override
protected int sizeOf(String key, Bitmap value) {
    return value.getRowBytes() * value.getHeight() / 1024;
}
 
Example 17
Project: boohee_v5.6   File: BitmapCompat.java   View Source Code Vote up 4 votes
public int getAllocationByteCount(Bitmap bitmap) {
    return bitmap.getRowBytes() * bitmap.getHeight();
}
 
Example 18
Project: BrewBook   File: LruBitmapCache.java   View Source Code Vote up 4 votes
@Override
protected int sizeOf(String key, Bitmap value) {
    return value.getRowBytes() * value.getHeight() / 1024;
}
 
Example 19
Project: techstar-org   File: MemoryCache.java   View Source Code Vote up 4 votes
long getSizeInBytes(Bitmap bitmap) {
    if(bitmap==null)
        return 0;
    return bitmap.getRowBytes() * bitmap.getHeight();
}
 
Example 20
Project: Pluto-Android   File: BitmapCommonUtils.java   View Source Code Vote up 2 votes
/**
 * 获取bitmap的字节大小
 * @param bitmap
 * @return
 */
public static int getBitmapSize(Bitmap bitmap) {
    return bitmap.getRowBytes() * bitmap.getHeight();
}