Java tutorial
//package com.java2s; //License from project: Apache License import android.graphics.Bitmap; import android.graphics.Bitmap.Config; import android.os.Build; public class Main { public static int getByteCount(Bitmap bitmap) { if (Build.VERSION.SDK_INT >= 19) { return bitmap.getAllocationByteCount(); } else if (Build.VERSION.SDK_INT >= 12) { return bitmap.getByteCount(); } else { return getByteCount(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig()); } } public static int getByteCount(int width, int height, Config config) { final int bytesPerPixel = (config.equals(Config.ARGB_8888) ? 4 : 2); return width * height * bytesPerPixel; } }