android.graphics.Bitmap Java Examples

The following examples show how to use android.graphics.Bitmap. 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: PictureWallChoose.java    From MainScreenShow with GNU General Public License v2.0 7 votes vote down vote up
/**
 * 优得到的采样率对图片进行解析
 *
 * @param filename
 * @param reqWidth
 * @return
 */
public static Bitmap decodeSampledBitmapFromFile(String filename,
                                                 int reqWidth) {

    // First decode with inJustDecodeBounds=true to check dimensions
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(filename, options);

    // Calculate inSampleSize
    options.inSampleSize = calculateInSampleSize(options, reqWidth);

    // Decode bitmap with inSampleSize set
    options.inJustDecodeBounds = false;
    return BitmapFactory.decodeFile(filename, options);
}
 
Example #2
Source File: IconsManager.java    From LaunchEnr with GNU General Public License v3.0 7 votes vote down vote up
Bitmap getDefaultAppDrawable(String packageName) {
    Drawable drawable = null;
    try {
        drawable = mPackageManager.getApplicationIcon(mPackageManager.getApplicationInfo(
                packageName, 0));
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
    if (drawable == null) {
        return null;
    }
    if (drawable instanceof BitmapDrawable) {
        return generateBitmap(((BitmapDrawable) drawable).getBitmap());
    }
    return generateBitmap(Bitmap.createBitmap(drawable.getIntrinsicWidth(),
            drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888));
}
 
Example #3
Source File: BitmapUtil.java    From VCL-Android with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.KITKAT)
static boolean canUseForInBitmap(
        Bitmap candidate, BitmapFactory.Options targetOptions) {

    if (candidate == null)
        return false;

    if (AndroidUtil.isKitKatOrLater()) {
        if (targetOptions.inSampleSize == 0)
            return false;
        // 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.getAllocationByteCount();
    }

    // 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;
}
 
Example #4
Source File: RoundedDrawable.java    From ClipCircleHeadLikeQQ with Apache License 2.0 6 votes vote down vote up
public RoundedDrawable(Bitmap bitmap) {
  mBitmap = bitmap;

  mBitmapWidth = bitmap.getWidth();
  mBitmapHeight = bitmap.getHeight();
  mBitmapRect.set(0, 0, mBitmapWidth, mBitmapHeight);

  mBitmapPaint = new Paint();
  mBitmapPaint.setStyle(Paint.Style.FILL);
  mBitmapPaint.setAntiAlias(true);

  mBorderPaint = new Paint();
  mBorderPaint.setStyle(Paint.Style.STROKE);
  mBorderPaint.setAntiAlias(true);
  mBorderPaint.setColor(mBorderColor.getColorForState(getState(), DEFAULT_BORDER_COLOR));
  mBorderPaint.setStrokeWidth(mBorderWidth);
}
 
Example #5
Source File: Crossfade.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private void captureValues(TransitionValues transitionValues) {
    View view = transitionValues.view;
    Rect bounds = new Rect(0, 0, view.getWidth(), view.getHeight());
    if (mFadeBehavior != FADE_BEHAVIOR_REVEAL) {
        bounds.offset(view.getLeft(), view.getTop());
    }
    transitionValues.values.put(PROPNAME_BOUNDS, bounds);

    if (Transition.DBG) {
        Log.d(LOG_TAG, "Captured bounds " + transitionValues.values.get(PROPNAME_BOUNDS));
    }
    Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(),
            Bitmap.Config.ARGB_8888);
    if (view instanceof TextureView) {
        bitmap = ((TextureView) view).getBitmap();
    } else {
        Canvas c = new Canvas(bitmap);
        view.draw(c);
    }
    transitionValues.values.put(PROPNAME_BITMAP, bitmap);
    // TODO: I don't have resources, can't call the non-deprecated method?
    BitmapDrawable drawable = new BitmapDrawable(bitmap);
    // TODO: lrtb will be wrong if the view has transXY set
    drawable.setBounds(bounds);
    transitionValues.values.put(PROPNAME_DRAWABLE, drawable);
}
 
Example #6
Source File: VMBitmap.java    From VMLibrary with Apache License 2.0 6 votes vote down vote up
/**
 * 等比例压缩到指定尺寸 默认到 1920 以下
 *
 * @param path 图片路径
 */
public static Bitmap compressByDimension(String path) {
    BitmapFactory.Options options = new BitmapFactory.Options();
    // 开始读入图片,此时把options.inJustDecodeBounds 设回true了
    options.inJustDecodeBounds = true;
    // 此时返回 bitmap 为空,并不会真正的加载图片
    Bitmap bitmap = BitmapFactory.decodeFile(path, options);
    options.inJustDecodeBounds = false;
    int w = options.outWidth;
    int h = options.outHeight;
    // 缩放比,由于是固定比例缩放,只用高或者宽其中一个数据进行计算即可
    int be = getZoomScale(w, h, maxDimension);
    // 设置缩放比例
    options.inSampleSize = be;
    // 重新读入图片,注意此时已经把options.inJustDecodeBounds 设回false了
    bitmap = BitmapFactory.decodeFile(path, options);
    // 等比例压缩后再进行质量压缩
    return bitmap;
}
 
Example #7
Source File: BitmapActivity.java    From android-combination-avatar with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_bitmap);

    mImageView1 = (ImageView) findViewById(R.id.imageView1);
    mImageView2 = (ImageView) findViewById(R.id.imageView2);
    mImageView3 = (ImageView) findViewById(R.id.imageView3);
    mImageView4 = (ImageView) findViewById(R.id.imageView4);

    Bitmap avatar1 = BitmapFactory.decodeResource(getResources(), R.drawable.headshow1);
    Bitmap avatar2 = BitmapFactory.decodeResource(getResources(), R.drawable.headshow2);
    Bitmap avatar3 = BitmapFactory.decodeResource(getResources(), R.drawable.headshow3);

    mBmps.add(avatar1);
    mBmps.add(avatar2);
    mBmps.add(avatar3);
}
 
Example #8
Source File: PlayPauseButton.java    From MusicBobber with MIT License 6 votes vote down vote up
public void albumCover(Drawable newAlbumCover) {
       if(this.albumCover == newAlbumCover) return;
       this.albumCover = newAlbumCover;

       if(albumCover instanceof BitmapDrawable && !isNeedToFillAlbumCoverMap.containsKey(albumCover.hashCode())) {
           Bitmap bitmap = ((BitmapDrawable) albumCover).getBitmap();
           if(bitmap != null && !bitmap.isRecycled()) {
               if(lastPaletteAsyncTask != null && !lastPaletteAsyncTask.isCancelled()) {
                   lastPaletteAsyncTask.cancel(true);
               }
               lastPaletteAsyncTask = Palette.from(bitmap).generate(palette -> {
                   int dominantColor = palette.getDominantColor(Integer.MAX_VALUE);
                   if(dominantColor != Integer.MAX_VALUE) {
					Color.colorToHSV(dominantColor, hsvArray);
					isNeedToFillAlbumCoverMap.put(albumCover.hashCode(), hsvArray[2] > 0.65f);
                       postInvalidate();
                   }
               });
           }
       }
       postInvalidate();
}
 
Example #9
Source File: ThumbnailAdapter.java    From remoteyourcam-usb with Apache License 2.0 6 votes vote down vote up
public void addFront(int objectHandle, String filename, Bitmap thumbnail) {
    if (maxNumPictures == 0) {
        if (thumbnail != null) {
            thumbnail.recycle();
        }
        return;
    }
    for (Integer i : handles) {
        if (i == objectHandle) {
            return;
        }
    }
    handles.add(objectHandle);
    thumbnails.add(thumbnail);
    filenames.add(filename);
    checkListSizes();
    notifyDataSetChanged();
}
 
Example #10
Source File: MyHttpTileDataSource.java    From hellomap3d-android with MIT License 6 votes vote down vote up
public TileData loadTile(MapTile tile) {

		String urlString = super.buildTileUrl(tile);

        Log.debug("requesting tile: "+urlString);

        Bitmap bmp = null;
        try {
            URL url = new URL(urlString);
            bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }

        return new TileData(BitmapUtils.createBitmapFromAndroidBitmap(bmp).compressToInternal());
	}
 
Example #11
Source File: FlyoutMenuView.java    From FlyoutMenus with MIT License 6 votes vote down vote up
Bitmap createMenuShadowBitmap() {
	menuShadowRadius = (int) flyoutMenuView.menuElevation * 2;
	menuShadowInset = menuShadowRadius / 2;
	int size = 2 * menuShadowRadius + 1;
	Bitmap shadowBitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
	shadowBitmap.eraseColor(0x0); // clear

	Paint paint = new Paint();
	paint.setAntiAlias(true);
	paint.setShader(new RadialGradient(
			menuShadowRadius + 1,
			menuShadowRadius + 1,
			menuShadowRadius,
			ColorUtils.setAlphaComponent(SHADOW_COLOR, SHADOW_ALPHA),
			ColorUtils.setAlphaComponent(SHADOW_COLOR, 0),
			Shader.TileMode.CLAMP));

	Canvas canvas = new Canvas(shadowBitmap);
	canvas.drawRect(0, 0, size, size, paint);

	return shadowBitmap;
}
 
Example #12
Source File: RoundedCornersTransformation.java    From glide-transformations with Apache License 2.0 6 votes vote down vote up
@Override
protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
                           @NonNull Bitmap toTransform, int outWidth, int outHeight) {
  int width = toTransform.getWidth();
  int height = toTransform.getHeight();

  Bitmap bitmap = pool.get(width, height, Bitmap.Config.ARGB_8888);
  bitmap.setHasAlpha(true);

  setCanvasBitmapDensity(toTransform, bitmap);

  Canvas canvas = new Canvas(bitmap);
  Paint paint = new Paint();
  paint.setAntiAlias(true);
  paint.setShader(new BitmapShader(toTransform, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
  drawRoundRect(canvas, paint, width, height);
  return bitmap;
}
 
Example #13
Source File: CustomNotificationBuilder.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Shows the work profile badge if it is needed.
 */
private void addWorkProfileBadge(RemoteViews view) {
    Resources resources = mContext.getResources();
    DisplayMetrics metrics = resources.getDisplayMetrics();
    int size = dpToPx(WORK_PROFILE_BADGE_SIZE_DP, metrics);
    int[] colors = new int[size * size];

    // Create an immutable bitmap, so that it can not be reused for painting a badge into it.
    Bitmap bitmap = Bitmap.createBitmap(colors, size, size, Bitmap.Config.ARGB_8888);

    Drawable inputDrawable = new BitmapDrawable(resources, bitmap);
    Drawable outputDrawable = ApiCompatibilityUtils.getUserBadgedDrawableForDensity(
            mContext, inputDrawable, null /* badgeLocation */, metrics.densityDpi);

    // The input bitmap is immutable, so the output drawable will be a different instance from
    // the input drawable if the work profile badge was applied.
    if (inputDrawable != outputDrawable && outputDrawable instanceof BitmapDrawable) {
        view.setImageViewBitmap(
                R.id.work_profile_badge, ((BitmapDrawable) outputDrawable).getBitmap());
        view.setViewVisibility(R.id.work_profile_badge, View.VISIBLE);
    }
}
 
Example #14
Source File: RegisterPhotoActivity.java    From Android with MIT License 6 votes vote down vote up
@Override
public void onPictureTaken(byte[] data, Camera camera) {
    takePhotoImg.setEnabled(true);
    file = FileUtil.byteArrayToFile(data,FileUtil.FileType.IMG);
    releasedCamera();
    if (file == null) {
        //no path to picture, return
        safeToTakePicture = true;
        return;
    }
    Bitmap bitmap = BitmapFactory.decodeFile(file.getPath());
    int w = bitmap.getWidth();
    int retY = toolbarTop.getHeight();
    int h = w;
    if (retY + w > bitmap.getHeight()) {
        h = bitmap.getHeight();
        retY = 0;
    }
    Bitmap cropBitmap = Bitmap.createBitmap(bitmap, 0, retY, w, h, null, false);
    File fileCrop = BitmapUtil.getInstance().bitmapSavePath(cropBitmap);
    FileUtil.deleteFile(file.getPath());
    PreviewPhotoActivity.startActivity(mActivity, fileCrop.getAbsolutePath());

    safeToTakePicture = true;
}
 
Example #15
Source File: DragGrid.java    From TopGrid with Apache License 2.0 5 votes vote down vote up
public void startDrag(Bitmap dragBitmap, int x, int y) {
        stopDrag();
        windowParams = new WindowManager.LayoutParams();// 获取WINDOW界面的
        //Gravity.TOP|Gravity.LEFT;这个必须加
        windowParams.gravity = Gravity.TOP | Gravity.LEFT;
//		windowParams.x = x - (int)((itemWidth / 2) * dragScale);
//		windowParams.y = y - (int) ((itemHeight / 2) * dragScale);
        //得到preview左上角相对于屏幕的坐标
        windowParams.x = x - win_view_x;
        windowParams.y = y - win_view_y;
//		this.windowParams.x = (x - this.win_view_x + this.viewX);//位置的x值
//		this.windowParams.y = (y - this.win_view_y + this.viewY);//位置的y值
        //设置拖拽item的宽和高
        windowParams.width = (int) (dragScale * dragBitmap.getWidth());// 放大dragScale倍,可以设置拖动后的倍数
        windowParams.height = (int) (dragScale * dragBitmap.getHeight());// 放大dragScale倍,可以设置拖动后的倍数
        this.windowParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
                | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
                | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
        this.windowParams.format = PixelFormat.TRANSLUCENT;
        this.windowParams.windowAnimations = 0;
        ImageView iv = new ImageView(getContext());
        iv.setImageBitmap(dragBitmap);
        windowManager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);// "window"
        windowManager.addView(iv, windowParams);
        dragImageView = iv;
    }
 
Example #16
Source File: FermiPlayerUtils.java    From FimiX8-RE with MIT License 5 votes vote down vote up
public static Bitmap createVideoThumbnail(String filePath, int width, int height, int offsetMillSecond) {
    Bitmap bitmap = createVideoThumbnail(filePath, offsetMillSecond);
    if (bitmap != null) {
        return ThumbnailUtils.extractThumbnail(bitmap, width, height);
    }
    return bitmap;
}
 
Example #17
Source File: TransitionAnimation.java    From iGap-Android with GNU Affero General Public License v3.0 5 votes vote down vote up
private static void setImageToView(View toView, Bitmap bitmap) {
    if (toView instanceof ImageView) {
        final ImageView toImageView = (ImageView) toView;
        toImageView.setImageBitmap(bitmap);
    } else {
        ViewCompat.setBackground(toView, new BitmapDrawable(toView.getResources(), bitmap));
    }
}
 
Example #18
Source File: LRULimitedMemoryCache.java    From BigApp_WordPress_Android with Apache License 2.0 5 votes vote down vote up
@Override
protected Bitmap removeNext() {
	Bitmap mostLongUsedValue = null;
	synchronized (lruCache) {
		Iterator<Entry<String, Bitmap>> it = lruCache.entrySet().iterator();
		if (it.hasNext()) {
			Entry<String, Bitmap> entry = it.next();
			mostLongUsedValue = entry.getValue();
			it.remove();
		}
	}
	return mostLongUsedValue;
}
 
Example #19
Source File: ImageUtils.java    From AndroidUtilCode with Apache License 2.0 5 votes vote down vote up
/**
 * Return the compressed data using quality.
 *
 * @param src     The source of bitmap.
 * @param quality The quality.
 * @param recycle True to recycle the source of bitmap, false otherwise.
 * @return the compressed data using quality
 */
public static byte[] compressByQuality(final Bitmap src,
                                       @IntRange(from = 0, to = 100) final int quality,
                                       final boolean recycle) {
    if (isEmptyBitmap(src)) return null;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    src.compress(Bitmap.CompressFormat.JPEG, quality, baos);
    byte[] bytes = baos.toByteArray();
    if (recycle && !src.isRecycled()) src.recycle();
    return bytes;
}
 
Example #20
Source File: PhotupImageView.java    From android-open-project-demo with Apache License 2.0 5 votes vote down vote up
public void runImpl() {
    final PhotupImageView imageView = mImageView.get();
    if (null == imageView) {
        return;
    }

    final Context context = imageView.getContext();
    final CacheableBitmapWrapper wrapper;

    final Bitmap bitmap = mFullSize ? mUpload.getDisplayImage(context)
            : mUpload.getThumbnailImage(context);

    if (null != bitmap) {
        final String key = mFullSize ? mUpload.getDisplayImageKey()
                : mUpload.getThumbnailImageKey();
        wrapper = new CacheableBitmapWrapper(key, bitmap);
    } else {
        wrapper = null;
    }

    // If we're interrupted, just update the cache and return
    if (isInterrupted()) {
        mCache.put(wrapper);
        return;
    }

    // If we're still running, update the Views
    if (null != wrapper) {
        imageView.post(new Runnable() {
            public void run() {
                imageView.setImageCachedBitmap(wrapper);
                mCache.put(wrapper);

                if (null != mListener) {
                    mListener.onPhotoLoadFinished(wrapper.getBitmap());
                }
            }
        });
    }
}
 
Example #21
Source File: BrowserUnit.java    From Ninja with Apache License 2.0 5 votes vote down vote up
public static boolean bitmap2File(Context context, Bitmap bitmap, String filename) {
    try {
        FileOutputStream fileOutputStream = context.openFileOutput(filename, Context.MODE_PRIVATE);
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, fileOutputStream);
        fileOutputStream.flush();
        fileOutputStream.close();
    } catch (Exception e) {
        return false;
    }

    return true;
}
 
Example #22
Source File: NativeElementView.java    From htmlview with Apache License 2.0 5 votes vote down vote up
static NativeElementView createImg(Context context, Element child) {
  // TODO: Focus / click handling for buttons in a link?
  ImageView imageView = new ImageView(context);
  NativeElementView wrapper = new NativeElementView(context, child, false, imageView);
  String src = child.getAttributeValue("src");
  if (src != null) {
    Bitmap image = child.htmlView.requestImage(
        child.htmlView.getAbsoluteUrl(src), wrapper, 
        HtmlView.ImageRequest.Type.REGULAR);
    if (image != null) {
      imageView.setImageBitmap(image);
    }
  }
  return wrapper;
}
 
Example #23
Source File: FunfactFragment.java    From Travel-Mate with MIT License 5 votes vote down vote up
/**
 * Takes screenshot of current screen
 *
 * @param view to be taken screenshot of
 * @return bitmap of the screenshot
 */
private static Bitmap getScreenShot(View view) {
    View screenView = view.getRootView();
    screenView.setDrawingCacheEnabled(true);
    Bitmap bitmap = Bitmap.createBitmap(screenView.getDrawingCache());
    screenView.setDrawingCacheEnabled(false);
    return bitmap;
}
 
Example #24
Source File: WebpBitmapFactoryTest.java    From fresco with MIT License 5 votes vote down vote up
@Test
public void testByteArrayDecode() throws Throwable {
  byte[] data = ByteStreams.toByteArray(getTestWebpInputStream());
  final Bitmap bitmap = mWebpBitmapFactory.decodeByteArray(data, 0, data.length, null);

  testBitmapDefault(bitmap, 20, 20);
}
 
Example #25
Source File: BitmapUtil.java    From SoloPi with Apache License 2.0 5 votes vote down vote up
/**
 * base64转为bitmap
 *
 * @param base64
 * @return
 */
public static Bitmap base64ToBitmap(byte[] base64) {
    if (base64 == null) {
        return null;
    }
    return BitmapFactory.decodeByteArray(base64, 0, base64.length);
}
 
Example #26
Source File: ShortcutHelper.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an intent that will add a shortcut to the home screen.
 * @param title Title of the shortcut.
 * @param icon Image that represents the shortcut.
 * @param shortcutIntent Intent to fire when the shortcut is activated.
 * @return Intent for the shortcut.
 */
public static Intent createAddToHomeIntent(String title, Bitmap icon,
        Intent shortcutIntent) {
    Intent i = new Intent(INSTALL_SHORTCUT);
    i.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    i.putExtra(Intent.EXTRA_SHORTCUT_NAME, title);
    i.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon);
    return i;
}
 
Example #27
Source File: ImageUtil.java    From Augendiagnose with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Utility method to change a bitmap colour.
 *
 * @param sourceBitmap The original bitmap
 * @param color        The target color
 * @return the bitmap with the target color.
 */
public static Bitmap changeBitmapColor(@NonNull final Bitmap sourceBitmap, final int color) {
	Bitmap ret = Bitmap.createBitmap(sourceBitmap.getWidth(), sourceBitmap.getHeight(), sourceBitmap.getConfig());

	Paint p = new Paint();
	ColorFilter filter = new LightingColorFilter(0, color);
	p.setAlpha(color >>> 24); // MAGIC_NUMBER
	p.setColorFilter(filter);
	Canvas canvas = new Canvas(ret);
	canvas.drawBitmap(sourceBitmap, 0, 0, p);
	return ret;
}
 
Example #28
Source File: CircularImageView.java    From arcusandroid with Apache License 2.0 5 votes vote down vote up
public void setImageBitmap (@Nullable Bitmap bitmap) {
    resizedCircularImage = bitmap;

    // Special case: remove image altogether
    if (bitmap == null) {
        super.setImageBitmap(null);
    } else {
        imageHeight = resizedCircularImage.getHeight();
        imageWidth = resizedCircularImage.getWidth();
        viewHeight = imageHeight + (bevelStrokeWidth * 2);
        viewWidth = imageWidth + (bevelStrokeWidth * 2);

        setBevelVisible(bevelVisible);
    }
}
 
Example #29
Source File: AccountManagementFragment.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new image with the picture overlaid by the badge.
 * @param userPicture A bitmap to overlay on.
 * @param badge A bitmap to overlay with.
 * @return A bitmap with the badge overlaying the {@code userPicture}.
 */
private static Bitmap overlayChildBadgeOnUserPicture(
        Bitmap userPicture, Bitmap badge, Resources resources) {
    assert userPicture.getWidth() == resources.getDimensionPixelSize(R.dimen.user_picture_size);
    int borderSize = resources.getDimensionPixelOffset(R.dimen.badge_border_size);
    int badgeRadius = resources.getDimensionPixelOffset(R.dimen.badge_radius);

    // Create a larger image to accommodate the badge which spills the original picture.
    int badgedPictureWidth =
            resources.getDimensionPixelOffset(R.dimen.badged_user_picture_width);
    int badgedPictureHeight =
            resources.getDimensionPixelOffset(R.dimen.badged_user_picture_height);
    Bitmap badgedPicture = Bitmap.createBitmap(badgedPictureWidth, badgedPictureHeight,
            Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(badgedPicture);
    canvas.drawBitmap(userPicture, 0, 0, null);

    // Cut a transparent hole through the background image.
    // This will serve as a border to the badge being overlaid.
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
    int badgeCenterX = badgedPictureWidth - badgeRadius;
    int badgeCenterY = badgedPictureHeight - badgeRadius;
    canvas.drawCircle(badgeCenterX, badgeCenterY, badgeRadius + borderSize, paint);

    // Draw the badge
    canvas.drawBitmap(badge, badgeCenterX - badgeRadius, badgeCenterY - badgeRadius, null);
    return badgedPicture;
}
 
Example #30
Source File: LimitedMemoryCache.java    From candybar with Apache License 2.0 5 votes vote down vote up
@Override
public Bitmap remove(String key) {
    Bitmap value = super.get(key);
    if (value != null) {
        if (hardCache.remove(value)) {
            cacheSize.addAndGet(-getSize(value));
        }
    }
    return super.remove(key);
}