List of usage examples for android.support.v4.graphics BitmapCompat getAllocationByteCount
public static int getAllocationByteCount(Bitmap bitmap)
From source file:com.squareup.picasso3.PlatformLruCache.java
void set(@NonNull String key, @NonNull Bitmap bitmap) { if (key == null || bitmap == null) { throw new NullPointerException("key == null || bitmap == null"); }/*from ww w. jav a 2 s. com*/ int byteCount = BitmapCompat.getAllocationByteCount(bitmap); // If the bitmap is too big for the cache, don't even attempt to store it. Doing so will cause // the cache to be cleared. Instead just evict an existing element with the same key if it // exists. if (byteCount > maxSize()) { cache.remove(key); return; } cache.put(key, new BitmapAndSize(bitmap, byteCount)); }
From source file:com.example.android.supportv4.media.AlbumArtCache.java
private AlbumArtCache() { // Holds no more than MAX_ALBUM_ART_CACHE_SIZE bytes, bounded by maxmemory/4 and // Integer.MAX_VALUE: int maxSize = Math.min(MAX_ALBUM_ART_CACHE_SIZE, (int) (Math.min(Integer.MAX_VALUE, Runtime.getRuntime().maxMemory() / 4))); mCache = new LruCache<String, Bitmap[]>(maxSize) { @Override/*from w ww .j a va 2s .co m*/ protected int sizeOf(String key, Bitmap[] value) { return BitmapCompat.getAllocationByteCount(value[BIG_BITMAP_INDEX]) + BitmapCompat.getAllocationByteCount(value[ICON_BITMAP_INDEX]); } }; }
From source file:com.crossbow.volley.toolbox.CrossbowImageCache.java
private static boolean canUseForInBitmap(Bitmap candidate, BitmapFactory.Options targetOptions) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (targetOptions.inSampleSize == 0) { final int width = targetOptions.outWidth; final int height = targetOptions.outHeight; final int byteCount = width * height * getBytesPerPixel(candidate.getConfig()); return byteCount <= BitmapCompat.getAllocationByteCount(candidate); }// ww w . j a v a 2 s. co m final int width = targetOptions.outWidth / targetOptions.inSampleSize; final int height = targetOptions.outHeight / targetOptions.inSampleSize; final int byteCount = width * height * getBytesPerPixel(candidate.getConfig()); return byteCount <= BitmapCompat.getAllocationByteCount(candidate); } return candidate.getWidth() == targetOptions.outWidth && candidate.getHeight() == targetOptions.outHeight && targetOptions.inSampleSize == 1; }
From source file:com.squareup.picasso3.Stats.java
private void processBitmap(Bitmap bitmap, int what) { // Never send bitmaps to the handler as they could be recycled before we process them. int bitmapSize = BitmapCompat.getAllocationByteCount(bitmap); handler.sendMessage(handler.obtainMessage(what, bitmapSize, 0)); }
From source file:my.home.lehome.asynctask.LoadProfileHeaderBgAsyncTask.java
@Override protected Bitmap doInBackground(Uri... uris) { if (uris == null || mImageView.get() == null || this.mContext.get() == null) return null; this.mUri = uris[0]; Bitmap resultBitmap = null;/*from w w w . j a va2 s . c o m*/ String saveURL = FileUtil.getPathFromUri(this.mContext.get(), mUri); if (!saveURL.endsWith("nav_thumb.png")) { Log.d(TAG, "need to create thumbnail: " + saveURL); Bitmap bitmap; BitmapFactory.Options decodeOptions = new BitmapFactory.Options(); InputStream imageStream = null; try { imageStream = this.mContext.get().getContentResolver().openInputStream(this.mUri); bitmap = BitmapFactory.decodeStream(imageStream, null, decodeOptions); } catch (FileNotFoundException e) { e.printStackTrace(); return null; } finally { if (imageStream != null) { try { imageStream.close(); } catch (IOException e) { Log.e(TAG, "could not close imageStream ", e); } } } String path = FileUtil.getPathFromUri(mContext.get(), this.mUri); resultBitmap = ImageUtil.scaleAndRotateImageFile(bitmap, path, this.mWidth, this.mHeight, this.mScaleType); Log.d(TAG, "scaled bitmap from " + BitmapCompat.getAllocationByteCount(bitmap) + "byte to " + BitmapCompat.getAllocationByteCount(resultBitmap) + "byte"); bitmap.recycle(); try { if (FileUtil.isExternalStorageWritable()) { File dstDir = FileUtil.getPictureStorageDir(THUMBNAIL_SAVE_DIR); saveURL = dstDir.getAbsolutePath() + File.separator + "nav_thumb.png"; ImageUtil.saveBitmapToFile(resultBitmap, saveURL, Bitmap.CompressFormat.PNG, 100); } else { Log.w(TAG, "isExternalStorageWritable false"); } } catch (FileNotFoundException | IllegalStateException e) { e.printStackTrace(); } PrefUtil.setStringValue(mContext.get(), PREF_KEY_PROFILE_IMAGE, saveURL); } else { Log.d(TAG, "use thumbnail: " + saveURL); resultBitmap = ImageUtil.loadBitmapFromFile(saveURL); } return resultBitmap; }