List of usage examples for android.graphics Bitmap getByteCount
public final int getByteCount()
From source file:com.miaotu.imutil.video.ImageCache.java
/** * @param candidate/* w w w .j av a 2s .c o m*/ * - Bitmap to check * @param targetOptions * - Options that have the out* value populated * @return true if <code>candidate</code> can be used for inBitmap re-use * with <code>targetOptions</code> */ @TargetApi(19) private static boolean canUseForInBitmap(Bitmap candidate, BitmapFactory.Options targetOptions) { // BEGIN_INCLUDE(can_use_for_inbitmap) if (!Util.hasKitKat()) { // On earlier versions, the dimensions must match exactly and the // inSampleSize must be 1 return candidate.getWidth() == targetOptions.outWidth && candidate.getHeight() == targetOptions.outHeight && targetOptions.inSampleSize == 1; } // From Android 4.4 (KitKat) onward we can re-use if the byte size of // the new bitmap // is smaller than the reusable bitmap candidate allocation byte count. int width = targetOptions.outWidth / targetOptions.inSampleSize; int height = targetOptions.outHeight / targetOptions.inSampleSize; int byteCount = width * height * getBytesPerPixel(candidate.getConfig()); return byteCount <= candidate.getByteCount(); // END_INCLUDE(can_use_for_inbitmap) }
From source file:com.wewe.android.util.video.ImageCache.java
/** * @param candidate//from w w w . ja va 2s .c o m * - Bitmap to check * @param targetOptions * - Options that have the out* value populated * @return true if <code>candidate</code> can be used for inBitmap re-use * with <code>targetOptions</code> */ @TargetApi(19) private static boolean canUseForInBitmap(Bitmap candidate, BitmapFactory.Options targetOptions) { // BEGIN_INCLUDE(can_use_for_inbitmap) if (!VersionUtil.hasKitKat()) { // On earlier versions, the dimensions must match exactly and the // inSampleSize must be 1 return candidate.getWidth() == targetOptions.outWidth && candidate.getHeight() == targetOptions.outHeight && targetOptions.inSampleSize == 1; } // From Android 4.4 (KitKat) onward we can re-use if the byte size of // the new bitmap // is smaller than the reusable bitmap candidate allocation byte count. int width = targetOptions.outWidth / targetOptions.inSampleSize; int height = targetOptions.outHeight / targetOptions.inSampleSize; int byteCount = width * height * getBytesPerPixel(candidate.getConfig()); return byteCount <= candidate.getByteCount(); // END_INCLUDE(can_use_for_inbitmap) }
From source file:org.videolan.vlc.gui.tv.RecommendationsService.java
private boolean doRecommendations() { mNotificationManager.cancelAll();//from w ww .j ava 2 s . c o m String last = Uri.decode(PreferenceManager.getDefaultSharedPreferences(mContext) .getString(PreferencesActivity.VIDEO_LAST, null)); int id = 0; if (last != null) { buildRecommendation(MediaLibrary.getInstance().getMediaItem(last), id, Notification.PRIORITY_HIGH); } ArrayList<MediaWrapper> videoList = MediaLibrary.getInstance().getVideoItems(); if (videoList == null || videoList.isEmpty()) return false; Bitmap pic; Collections.shuffle(videoList); for (MediaWrapper mediaWrapper : videoList) { if (TextUtils.equals(mediaWrapper.getLocation(), last)) continue; pic = mMediaDatabase.getPicture(mediaWrapper.getUri()); if (pic != null && pic.getByteCount() > 4 && mediaWrapper.getTime() == 0) { buildRecommendation(mediaWrapper, ++id, Notification.PRIORITY_DEFAULT); } if (id == NUM_RECOMMANDATIONS) break; } return true; }
From source file:com.concentricsky.android.khanacademy.util.ThumbnailManager.java
private LruCache<Thumbnail, Bitmap> prepareCache() { // Total available heap size. This changes based on manifest android:largeHeap="true". (Fire HD, transformer both go from 48MB to 256MB) Runtime rt = Runtime.getRuntime(); long maxMemory = rt.maxMemory(); Log.v(LOG_TAG, "maxMemory:" + Long.toString(maxMemory)); // Want to use at most about 1/2 of available memory for thumbs. // In SAT Math category (116 videos), with a heap size of 48MB, this setting // allows 109 thumbs to be cached resulting in total heap usage around 34MB. long usableMemory = maxMemory / 2; return new LruCache<Thumbnail, Bitmap>((int) usableMemory) { @Override/* ww w . ja v a 2s.co m*/ protected int sizeOf(Thumbnail key, Bitmap value) { return value.getByteCount(); } @Override protected void entryRemoved(boolean evicted, Thumbnail key, Bitmap oldValue, Bitmap newValue) { if (oldValue != newValue) { oldValue.recycle(); } } }; }
From source file:com.easemob.chatui.video.util.ImageCache.java
/** * @param candidate/*from w w w . jav a 2s. co m*/ * - Bitmap to check * @param targetOptions * - Options that have the out* value populated * @return true if <code>candidate</code> can be used for inBitmap re-use * with <code>targetOptions</code> */ @TargetApi(19) private static boolean canUseForInBitmap(Bitmap candidate, BitmapFactory.Options targetOptions) { // BEGIN_INCLUDE(can_use_for_inbitmap) if (!com.easemob.chatui.video.util.Utils.hasKitKat()) { // On earlier versions, the dimensions must match exactly and the // inSampleSize must be 1 return candidate.getWidth() == targetOptions.outWidth && candidate.getHeight() == targetOptions.outHeight && targetOptions.inSampleSize == 1; } // From Android 4.4 (KitKat) onward we can re-use if the byte size of // the new bitmap // is smaller than the reusable bitmap candidate allocation byte count. int width = targetOptions.outWidth / targetOptions.inSampleSize; int height = targetOptions.outHeight / targetOptions.inSampleSize; int byteCount = width * height * getBytesPerPixel(candidate.getConfig()); return byteCount <= candidate.getByteCount(); // END_INCLUDE(can_use_for_inbitmap) }
From source file:ch.carteggio.ui.ConversationIconLoader.java
/** * Constructor.//www . ja va 2 s .c om * * @param context * A {@link Context} instance. * @param defaultBackgroundColor * The ARGB value to be used as background color for the fallback picture. {@code 0} to * use a dynamically calculated background color. */ public ConversationIconLoader(Context context, int defaultBackgroundColor) { Context appContext = context.getApplicationContext(); mContentResolver = appContext.getContentResolver(); mResources = appContext.getResources(); mHelper = new CarteggioProviderHelper(appContext); float scale = mResources.getDisplayMetrics().density; mPictureSizeInPx = (int) (PICTURE_SIZE * scale); mDefaultBackgroundColor = defaultBackgroundColor; ActivityManager activityManager = (ActivityManager) appContext.getSystemService(Context.ACTIVITY_SERVICE); int memClass = activityManager.getMemoryClass(); // Use 1/16th of the available memory for this memory cache. final int cacheSize = 1024 * 1024 * memClass / 16; mBitmapCache = new LruCache<Long, Bitmap>(cacheSize) { @Override protected int sizeOf(Long key, Bitmap bitmap) { // The cache size will be measured in bytes rather than number of items. return bitmap.getByteCount(); } }; }
From source file:com.example.imagedownloader.ImageDownloader.java
public ImageDownloader(Activity actv) { imagesDirectory = Storage.getImagesDirectory(); if (withRetainFragment) { RetainFragment mRetainFragment = RetainFragment.findOrCreateRetainFragment(actv.getFragmentManager()); mMemoryCache = RetainFragment.mRetainedCache; if (mMemoryCache == null) { mMemoryCache = new LruCache<String, Bitmap>(cacheSize) { @Override/*from w w w . java 2 s. c om*/ protected int sizeOf(String key, Bitmap bitmap) { return bitmap.getByteCount() / 1024; } }; mRetainFragment.mRetainedCache = mMemoryCache; } } else { mMemoryCache = new LruCache<String, Bitmap>(cacheSize) { @Override protected int sizeOf(String key, Bitmap bitmap) { return bitmap.getByteCount() / 1024; } }; } File diskCacheDir = Storage.getDiskCacheDirectory(IMG_W, IMG_H); Log.d(LOG_TAG, "DISK cache Dir: " + diskCacheDir); new InitDiskCacheTask().execute(diskCacheDir); //------------------------------------------------------ END OF INIT CACHE }
From source file:android.bitmap.util.ImageCache.java
/** * @param candidate - Bitmap to check// ww w . j a va 2s .co m * @param targetOptions - Options that have the out* value populated * @return true if <code>candidate</code> can be used for inBitmap re-use with * <code>targetOptions</code> */ @SuppressLint("NewApi") @TargetApi(VERSION_CODES.GINGERBREAD_MR1) private static boolean canUseForInBitmap(Bitmap candidate, BitmapFactory.Options targetOptions) { if (!Utils.hasKitKat()) { // On earlier versions, the dimensions must match exactly and the inSampleSize must be 1 return candidate.getWidth() == targetOptions.outWidth && candidate.getHeight() == targetOptions.outHeight && targetOptions.inSampleSize == 1; } // From Android 4.4 (KitKat) onward we can re-use if the byte size of the new bitmap // is smaller than the reusable bitmap candidate allocation byte count. int width = targetOptions.outWidth / targetOptions.inSampleSize; int height = targetOptions.outHeight / targetOptions.inSampleSize; int byteCount = width * height * getBytesPerPixel(candidate.getConfig()); return byteCount <= candidate.getByteCount(); }
From source file:co.tinode.tindroid.ImageLoader.java
protected ImageLoader(Context context, int imageSize, FragmentManager fm) { mResources = context.getResources(); mImageSize = imageSize;//from w ww. jav a 2 s .c o m final RetainFragment mRetainFragment = findOrCreateRetainFragment(fm); // See if we already have an ImageCache stored in RetainFragment mBitmapCache = (LruCache<String, Bitmap>) mRetainFragment.getObject(); // No existing ImageCache, create one and store it in RetainFragment if (mBitmapCache == null) { int maxSize = Math.round(MEMORY_PERCENT * Runtime.getRuntime().maxMemory() / 1024); mBitmapCache = new LruCache<String, Bitmap>(maxSize) { /** * Measure item size in kilobytes rather than units which is more practical * for a bitmap cache */ @Override protected int sizeOf(String key, Bitmap bitmap) { final int bitmapSize = bitmap.getByteCount() / 1024; return bitmapSize == 0 ? 1 : bitmapSize; } }; mRetainFragment.saveObject(mBitmapCache); } }
From source file:com.projectattitude.projectattitude.Activities.ViewProfileActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == 1 && resultCode == RESULT_OK && data != null && data.getData() != null) { Uri uri = data.getData();//ww w .j a v a2s. c o m try { Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri); // Log.d(TAG, String.valueOf(bitmap)); Log.d("PhotoBytes1", bitmap.getByteCount() + ""); Log.d("PhotoHeight1", bitmap.getHeight() + ""); Log.d("PhotoHeight1", bitmap.getWidth() + ""); //if greater then byte threshold, compress if (bitmap.getByteCount() > 65536) { while (bitmap.getByteCount() > 65536) { //Keep compressing photo until photo is small enough bitmap = Bitmap.createScaledBitmap(bitmap, (bitmap.getWidth() / 2), (bitmap.getHeight() / 2), false); Log.d("imageCompressed", bitmap.getByteCount() + ""); } } ByteArrayOutputStream stream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream); byte[] byteArray = stream.toByteArray(); s = Base64.encodeToString(byteArray, Base64.DEFAULT); image.setImageBitmap(bitmap); user.setPhoto(s); //TODO Update the database } catch (IOException e) { e.printStackTrace(); } //TODO: Update user with profile picture userController.getActiveUser().setPhoto(s); ElasticSearchUserController.UpdateUserPictureTask updateUserPictureTask = new ElasticSearchUserController.UpdateUserPictureTask(); updateUserPictureTask.execute(UserController.getInstance().getActiveUser()); } }