Example usage for android.graphics Bitmap getByteCount

List of usage examples for android.graphics Bitmap getByteCount

Introduction

In this page you can find the example usage for android.graphics Bitmap getByteCount.

Prototype

public final int getByteCount() 

Source Link

Document

Returns the minimum number of bytes that can be used to store this bitmap's pixels.

Usage

From source file:Main.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
public static int getSizeInBytes(Bitmap bitmap) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
        return bitmap.getByteCount();
    } else {/* w w w . ja  v a2 s . c  om*/
        return bitmap.getRowBytes() * bitmap.getHeight();
    }
}

From source file:Main.java

@TargetApi(12)
public static int getBitmapSize(Bitmap bitmap) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
        return bitmap.getByteCount();
    }/*from   w w w  . j  ava 2 s . co m*/
    // Pre HC-MR1
    return bitmap.getRowBytes() * bitmap.getHeight();
}

From source file:Main.java

@SuppressLint("NewApi")
public static void onTrimMemory(int level) {
    int count = 0;
    if (level >= ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
        count = 10;// w ww  . j av  a 2 s.  c  o m
        if (level >= ComponentCallbacks2.TRIM_MEMORY_BACKGROUND) {
            count = 0;
        }
    } else
        return;

    int size = 0;
    if (count > 0) {
        for (Bitmap b : placeHolders) {
            size += b.getByteCount();
        }
    }

    int trimSize = placeHolders.size() == 0 ? 0 : ((count * size) / placeHolders.size());
    Log.v(TAG, "trim image cache from " + memCache.size() + " to " + trimSize
            + " to reduce memory usage, max size " + memCache.maxSize());
    memCache.trimToSize(trimSize);
}

From source file:Main.java

/**
 * Get the size in bytes of a bitmap.// w ww  .j  av  a2  s .c o  m
 * @param bitmap
 * @return size in bytes
 */
public static int getBitmapSize(Bitmap bitmap) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
        return bitmap.getByteCount();
    }
    // Pre HC-MR1
    return bitmap.getRowBytes() * bitmap.getHeight();
}

From source file:Main.java

public static long getBitmapsize(Bitmap bitmap) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
        return bitmap.getByteCount();
    }/*from w  ww.  j a v a2 s . c  om*/
    // Pre HC-MR1
    return bitmap.getRowBytes() * bitmap.getHeight();

}

From source file:Main.java

public static Bitmap decodeSampleBitMapFromResource(Context context, int resId, int reqWidth, int reqHeight) {
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;/*ww  w  . j  a v a2 s.c  o m*/
    BitmapFactory.decodeResource(context.getResources(), resId, options);
    options = sampleBitmapOptions(context, options, reqWidth, reqHeight);
    Bitmap bm = BitmapFactory.decodeResource(context.getResources(), resId, options);
    Log.e("xxx", bm.getByteCount() + "");
    return bm;
}

From source file:Main.java

public static int getDrawableSize(Drawable drawable) {
    if (drawable == null) {
        return 0;
    }/*from  www  .  j a  va2  s .  com*/
    Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
        return bitmap.getByteCount();
    } else {
        return bitmap.getRowBytes() * bitmap.getHeight();
    }
}

From source file:Main.java

/**
 * //ww w  .ja va  2s. c om
 * @return Bitmap's RGBA byte array
 */
public static byte[] getImageRGBA(Bitmap inputBitmap) {
    Config config = inputBitmap.getConfig();
    ByteBuffer buffer;

    Bitmap bitmap;
    /**
     * if bitmap size is not 32*32 create scaled bitmap
     */

    if (inputBitmap.getWidth() != 32 || inputBitmap.getHeight() != 32) {
        Log.d(TAG, "bitmap resized to 32x32");
        bitmap = Bitmap.createScaledBitmap(inputBitmap, 32, 32, false);
    } else {
        bitmap = inputBitmap;
    }
    /**
     * if bitmap is not ARGB_8888 format, copy bitmap with ARGB_8888 format
     */
    if (!config.equals(Bitmap.Config.ARGB_8888)) {
        Bitmap bitmapARBG = bitmap.copy(Bitmap.Config.ARGB_8888, false);
        buffer = ByteBuffer.allocate(bitmapARBG.getByteCount());
        bitmapARBG.copyPixelsToBuffer(buffer);
        bitmapARBG.recycle();
    } else {
        buffer = ByteBuffer.allocate(bitmap.getByteCount());
        bitmap.copyPixelsToBuffer(buffer);
    }
    return buffer.array();
}

From source file:Main.java

public static Bitmap scaleBitmap(Bitmap source, int targetSize) {
    int sourceW = source.getWidth();
    int sourceH = source.getHeight();

    float scaleFactor = (float) Math.sqrt(source.getByteCount() / targetSize);

    int dstWidth = (int) (sourceW / scaleFactor);
    int dstHeight = (int) (sourceH / scaleFactor);

    Bitmap scaledBitmap = createScaledBitmap(source, dstWidth, dstHeight, true);
    return scaledBitmap;
}

From source file:binh.app.englishidiom.ImageCache.java

public static int getBitmapSize(Bitmap bitmap) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1)
        return bitmap.getByteCount();
    // Pre HC-MR1
    return bitmap.getRowBytes() * bitmap.getHeight();
}