Java Code Examples for android.graphics.Bitmap#getByteCount()
The following examples show how to use
android.graphics.Bitmap#getByteCount() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImageProvider.java From cube-sdk with Apache License 2.0 | 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(19) // @TargetApi(VERSION_CODES.KITKAT) public static long getBitmapSize(BitmapDrawable value) { if (null == value) { return 0; } Bitmap bitmap = value.getBitmap(); // From KitKat onward use getAllocationByteCount() as allocated bytes can potentially be // larger than bitmap byte count. if (Version.hasKitKat()) { return bitmap.getAllocationByteCount(); } if (Version.hasHoneycombMR1()) { return bitmap.getByteCount(); } // Pre HC-MR1 return bitmap.getRowBytes() * bitmap.getHeight(); }
Example 2
Source File: ImageCache.java From malevich with MIT License | 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 (Malevich.Utils.hasKitKat()) { return bitmap.getAllocationByteCount(); } if (Malevich.Utils.hasHoneycombMR1()) { return bitmap.getByteCount(); } // Pre HC-MR1 return bitmap.getRowBytes() * bitmap.getHeight(); }
Example 3
Source File: Cache.java From tns-core-modules-widgets with Apache License 2.0 | 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 bitmap * @return size in bytes */ @TargetApi(VERSION_CODES.KITKAT) public static int getBitmapSize(Bitmap bitmap) { // 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 4
Source File: ImageCache.java From RoMote with Apache License 2.0 | 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 5
Source File: BitmapUtils.java From Simpler with Apache License 2.0 | 6 votes |
/** * 图片按比例大小压缩方法 * * @param bitmap * @param sizeM 图片大小(以MB为单位) * @return */ public static Bitmap getImage(Bitmap bitmap, int sizeM) { Bitmap bmp = bitmap; // 创建操作图片用的matrix对象 Matrix matrix = new Matrix(); // 获取这个图片的宽和高 do { float width = bmp.getWidth(); float height = bmp.getHeight(); // 缩放图片动作 matrix.postScale(0.8F, 0.8F); bmp = Bitmap.createBitmap(bmp, 0, 0, (int) width, (int) height, matrix, true); } while (bmp.getByteCount() > sizeM * 1024 * 1024); return bmp; }
Example 6
Source File: ImageCache.java From bither-bitmap-sample with Apache License 2.0 | 5 votes |
/** * Get the size in bytes of a bitmap. * * @param bitmap * @return size in bytes */ @TargetApi(12) public static int getBitmapSize(Bitmap bitmap) { if (Utils.hasHoneycombMR1()) { return bitmap.getByteCount(); } // Pre HC-MR1 return bitmap.getRowBytes() * bitmap.getHeight(); }
Example 7
Source File: SketchUtils.java From sketch with Apache License 2.0 | 5 votes |
/** * 获取 {@link Bitmap} 占用内存大小,单位字节 */ public static int getByteCount(@Nullable Bitmap bitmap) { // bitmap.isRecycled()过滤很关键,在4.4以及以下版本当bitmap已回收时调用其getAllocationByteCount()方法将直接崩溃 if (bitmap == null || bitmap.isRecycled()) { return 0; } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { return bitmap.getAllocationByteCount(); } else { return bitmap.getByteCount(); } }
Example 8
Source File: ImageCreator.java From wasp with Apache License 2.0 | 5 votes |
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1) private int getBitmapSize(Bitmap bitmap) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR1) { return bitmap.getRowBytes() * bitmap.getHeight(); } return bitmap.getByteCount(); }
Example 9
Source File: BitmapUtil.java From AndroidBasicProject with MIT License | 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 10
Source File: Utils.java From bubble with MIT License | 5 votes |
public static int calculateBitmapSize(Bitmap bitmap) { int sizeInBytes; if (Utils.isHoneycombMR1orLater()) { sizeInBytes = bitmap.getByteCount(); } else { sizeInBytes = bitmap.getRowBytes() * bitmap.getHeight(); } return sizeInBytes / 1024; }
Example 11
Source File: LegacySDKUtil.java From Dali with Apache License 2.0 | 5 votes |
/** * 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(); } }
Example 12
Source File: Thumbnail.java From UMS-Interface with GNU General Public License v3.0 | 5 votes |
public static int getBitmapSize(Bitmap bitmap) { int size = 0; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { size = bitmap.getAllocationByteCount(); }else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) { size = bitmap.getByteCount(); }else { size = bitmap.getWidth()*bitmap.getHeight()*3; } return size; }
Example 13
Source File: ImageCache.java From ListViewVariants with Apache License 2.0 | 5 votes |
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(); }
Example 14
Source File: BitmapUtil.java From PLDroidShortVideo with Apache License 2.0 | 5 votes |
public static byte[] loadPhotoRGBABytes(Bitmap bitmap) { if (bitmap == null) { return null; } byte[] bytes = new byte[bitmap.getByteCount()]; ByteBuffer rgbaBuffer = ByteBuffer.wrap(bytes); bitmap.copyPixelsToBuffer(rgbaBuffer); return bytes; }
Example 15
Source File: Utils.java From Ticket-Analysis with MIT License | 5 votes |
/** * Get the size in bytes of a bitmap. * * @param bitmap * @return size in bytes */ @TargetApi(12) public static int getBitmapSize(Bitmap bitmap) { if (Utils.hasHoneycombMR1()) { return bitmap.getByteCount(); } // Pre HC-MR1 return bitmap.getRowBytes() * bitmap.getHeight(); }
Example 16
Source File: TileBitmapDrawable.java From ByakuGallery with Apache License 2.0 | 5 votes |
@TargetApi(Build.VERSION_CODES.KITKAT) private static int getBitmapSize(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(); } return bitmap.getRowBytes() * bitmap.getHeight(); }
Example 17
Source File: BitmapLruCache.java From MultiView with Apache License 2.0 | 4 votes |
@Override protected int sizeOf(Uri key, Bitmap value) { return value.getByteCount() / 1024; }
Example 18
Source File: Image.java From J2ME-Loader with Apache License 2.0 | 4 votes |
@Override protected int sizeOf(String key, Bitmap value) { return value.getByteCount(); }
Example 19
Source File: ImageLoaderDebugTool.java From ImageLoader with Apache License 2.0 | 4 votes |
private static void findImageViewInViewTree(View curNode,List<ImageViewInfo> imageList) { if (curNode.getVisibility() != View.VISIBLE) { return ; } if (curNode instanceof ViewGroup) { ViewGroup curNodeGroup = (ViewGroup) curNode; for (int i = 0; i < curNodeGroup.getChildCount(); i++) { findImageViewInViewTree(curNodeGroup.getChildAt(i),imageList); } } else { if (curNode instanceof ImageView) { ImageViewInfo imageViewInfo = new ImageViewInfo(); ImageView curImage = (ImageView) curNode; Drawable drawable = curImage.getDrawable(); if (drawable instanceof BitmapDrawable) { Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap(); imageViewInfo.imageHeight = bitmap.getHeight(); imageViewInfo.imageWidth = bitmap.getWidth(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { //API 19 imageViewInfo.imageSize = bitmap.getAllocationByteCount(); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {//API 12 imageViewInfo.imageSize = bitmap.getByteCount(); } else { imageViewInfo.imageSize = bitmap.getRowBytes() * bitmap.getHeight(); } if(bitmap.getHeight() * bitmap.getWidth() > curImage.getMeasuredHeight() * curImage.getMeasuredWidth()){ imageViewInfo.imgViewInfo = MyUtil.printImageView(curImage); imageList.add(imageViewInfo); } }else { imageViewInfo.imageHeight = drawable.getIntrinsicHeight(); imageViewInfo.imageWidth = drawable.getIntrinsicWidth(); if(imageViewInfo.imageHeight * imageViewInfo.imageWidth > curImage.getMeasuredHeight() * curImage.getMeasuredWidth()){ imageViewInfo.imgViewInfo = MyUtil.printImageView(curImage); imageList.add(imageViewInfo); } } } } return ; }
Example 20
Source File: Utils.java From Android-ImageManager with MIT License | 4 votes |
public static int getSizeInBytes(final Bitmap bitmap) { return bitmap.getByteCount(); }