Java Code Examples for android.graphics.Bitmap#isPremultiplied()

The following examples show how to use android.graphics.Bitmap#isPremultiplied() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: android-tv-launcher   File: ImageTools.java    License: MIT License 6 votes vote down vote up
/**
 *图片阴影
 * @param originalBitmap
 */
public static Drawable drawImageDropShadow(Bitmap originalBitmap, Context context) {

    BlurMaskFilter blurFilter = new BlurMaskFilter(3,BlurMaskFilter.Blur.NORMAL);
    Paint shadowPaint = new Paint();
    shadowPaint.setAlpha(80);
    shadowPaint.setColor(context.getResources().getColor(R.color.black));
    shadowPaint.setMaskFilter(blurFilter);
    int[] offsetXY = new int[2];
    Bitmap shadowBitmap = originalBitmap.extractAlpha(shadowPaint, offsetXY);
    Bitmap shadowImage32 = shadowBitmap.copy(Bitmap.Config.ARGB_8888, true);
    if ( !shadowImage32.isPremultiplied() )
    {
        shadowImage32.setPremultiplied( true );
    }
    Canvas c = new Canvas(shadowImage32);
    c.drawBitmap(originalBitmap, offsetXY[0], offsetXY[1], null);
    return new BitmapDrawable(shadowImage32);
}
 
Example 2
Source Project: jus   File: NetworkImageView.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Checks if the bitmap is able to be drawn by a {@link Canvas}. If bit map is null it will
 * return true as this is fine and will be ignored anyway, while recycled bitmaps will cause an
 * Exception thrown
 */
protected static boolean isOk2Draw(Bitmap bitmap) {
    //ignore this if bitmap is null.
    if (bitmap == null) return true;

    if (bitmap.isRecycled()) {
        return false;
    }
    if (Build.VERSION.SDK_INT > 16) {
        if (!bitmap.isPremultiplied() && bitmap.getConfig() == Bitmap.Config.ARGB_8888 &&
                bitmap.hasAlpha()) {
            return false;
        }
    }

    return true;
}
 
Example 3
Source Project: android-openGL-canvas   File: CanvasGL.java    License: Apache License 2.0 5 votes vote down vote up
protected void throwIfCannotDraw(Bitmap bitmap) {
    if (bitmap.isRecycled()) {
        throw new RuntimeException("Canvas: trying to use a recycled bitmap " + bitmap);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        if (!bitmap.isPremultiplied() && bitmap.getConfig() == Bitmap.Config.ARGB_8888 &&
                bitmap.hasAlpha()) {
            throw new RuntimeException("Canvas: trying to use a non-premultiplied bitmap "
                    + bitmap);
        }
    }
}
 
Example 4
public boolean isBitmapRecycled(Bitmap bitmap) {
    if (android.os.Build.VERSION.SDK_INT < 17) {
        return bitmap.isRecycled();
    } else {
        return bitmap.isRecycled() || (!bitmap.isPremultiplied() && bitmap.getConfig() == Bitmap.Config.ARGB_8888 && bitmap.hasAlpha());
    }
}