Java Code Examples for android.graphics.Bitmap.extractAlpha()

The following are Jave code examples for showing how to use extractAlpha() of the android.graphics.Bitmap class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: LaunchEnr   File: ShadowGenerator.java   View Source Code Vote up 6 votes
public synchronized Bitmap recreateIcon(Bitmap icon) {
    int[] offset = new int[2];
    Bitmap shadow = icon.extractAlpha(mBlurPaint, offset);
    Bitmap result = Bitmap.createBitmap(mIconSize, mIconSize, Config.ARGB_8888);
    mCanvas.setBitmap(result);

    // Draw ambient shadow
    mDrawPaint.setAlpha(AMBIENT_SHADOW_ALPHA);
    mCanvas.drawBitmap(shadow, offset[0], offset[1], mDrawPaint);

    // Draw key shadow
    mDrawPaint.setAlpha(KEY_SHADOW_ALPHA);
    mCanvas.drawBitmap(shadow, offset[0], offset[1] + KEY_SHADOW_DISTANCE * mIconSize, mDrawPaint);

    // Draw the icon
    mDrawPaint.setAlpha(255);
    mCanvas.drawBitmap(icon, 0, 0, mDrawPaint);

    mCanvas.setBitmap(null);
    return result;
}
 
Example 2
Project: FreeStreams-TVLauncher   File: ImageTools.java   View Source Code Vote up 6 votes
/**
 *图片阴影
 * @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 3
Project: FlickLauncher   File: ShadowGenerator.java   View Source Code Vote up 6 votes
public synchronized Bitmap recreateIcon(Bitmap icon) {
    int[] offset = new int[2];
    Bitmap shadow = icon.extractAlpha(mBlurPaint, offset);
    Bitmap result = Bitmap.createBitmap(mIconSize, mIconSize, Config.ARGB_8888);
    mCanvas.setBitmap(result);

    // Draw ambient shadow
    mDrawPaint.setAlpha(AMBIENT_SHADOW_ALPHA);
    mCanvas.drawBitmap(shadow, offset[0], offset[1], mDrawPaint);

    // Draw key shadow
    mDrawPaint.setAlpha(KEY_SHADOW_ALPHA);
    mCanvas.drawBitmap(shadow, offset[0], offset[1] + KEY_SHADOW_DISTANCE * mIconSize, mDrawPaint);

    // Draw the icon
    mDrawPaint.setAlpha(255);
    mCanvas.drawBitmap(icon, 0, 0, mDrawPaint);

    mCanvas.setBitmap(null);
    return result;
}
 
Example 4
Project: SimpleUILauncher   File: ShadowGenerator.java   View Source Code Vote up 6 votes
public synchronized Bitmap recreateIcon(Bitmap icon) {
    int[] offset = new int[2];
    Bitmap shadow = icon.extractAlpha(mBlurPaint, offset);
    Bitmap result = Bitmap.createBitmap(mIconSize, mIconSize, Config.ARGB_8888);
    mCanvas.setBitmap(result);

    // Draw ambient shadow
    mDrawPaint.setAlpha(AMBIENT_SHADOW_ALPHA);
    mCanvas.drawBitmap(shadow, offset[0], offset[1], mDrawPaint);

    // Draw key shadow
    mDrawPaint.setAlpha(KEY_SHADOW_ALPHA);
    mCanvas.drawBitmap(shadow, offset[0], offset[1] + KEY_SHADOW_DISTANCE * mIconSize, mDrawPaint);

    // Draw the icon
    mDrawPaint.setAlpha(255);
    mCanvas.drawBitmap(icon, 0, 0, mDrawPaint);

    mCanvas.setBitmap(null);
    return result;
}
 
Example 5
Project: RLibrary   File: BmpUtil.java   View Source Code Vote up 6 votes
/**
 *  为指定图片增加阴影
 *
 * @param map     图片
 * @param radius  阴影的半径
 * @return bitmap
 */
public static Bitmap drawShadow(Bitmap map, int radius) {
    if (map == null)
        return null;

    BlurMaskFilter blurFilter = new BlurMaskFilter(radius, BlurMaskFilter.Blur.OUTER);
    Paint shadowPaint = new Paint();
    shadowPaint.setMaskFilter(blurFilter);

    int[] offsetXY = new int[2];
    Bitmap shadowImage = map.extractAlpha(shadowPaint, offsetXY);
    shadowImage = shadowImage.copy(Bitmap.Config.ARGB_8888, true);
    Canvas c = new Canvas(shadowImage);
    c.drawBitmap(map, -offsetXY[0], -offsetXY[1], null);
    return shadowImage;
}
 
Example 6
Project: BBSSDK-for-Android   File: ImageUtils.java   View Source Code Vote up 5 votes
/**
 * 转为alpha位图
 *
 * @param src     源图片
 * @param recycle 是否回收
 * @return alpha位图
 */
public static Bitmap toAlpha(final Bitmap src, final Boolean recycle) {
	if (isEmptyBitmap(src)) {
		return null;
	}
	Bitmap ret = src.extractAlpha();
	if (recycle && !src.isRecycled()) {
		src.recycle();
	}
	return ret;
}
 
Example 7
Project: LJFramework   File: ImageUtils.java   View Source Code Vote up 5 votes
/**
 * 转为alpha位图
 *
 * @param src 源图片
 * @param recycle 是否回收
 * @return alpha位图
 */
public static Bitmap toAlpha(Bitmap src, Boolean recycle) {
    if (isEmptyBitmap(src)) {
        return null;
    }
    Bitmap ret = src.extractAlpha();
    if (recycle && !src.isRecycled()) {
        src.recycle();
    }
    return ret;
}
 
Example 8
Project: LaunchEnr   File: HolographicOutlineHelper.java   View Source Code Vote up 4 votes
/**
 * Applies a more expensive and accurate outline to whatever is currently drawn in a specified
 * bitmap.
 */
public void applyExpensiveOutlineWithBlur(Bitmap srcDst, Canvas srcDstCanvas) {

    // We start by removing most of the alpha channel so as to ignore shadows, and
    // other types of partial transparency when defining the shape of the object
    byte[] pixels = new byte[srcDst.getWidth() * srcDst.getHeight()];
    ByteBuffer buffer = ByteBuffer.wrap(pixels);
    buffer.rewind();
    srcDst.copyPixelsToBuffer(buffer);

    for (int i = 0; i < pixels.length; i++) {
        if ((pixels[i] & 0xFF) < 188) {
            pixels[i] = 0;
        }
    }

    buffer.rewind();
    srcDst.copyPixelsFromBuffer(buffer);

    // calculate the outer blur first
    mBlurPaint.setMaskFilter(mMediumOuterBlurMaskFilter);
    int[] outerBlurOffset = new int[2];
    Bitmap thickOuterBlur = srcDst.extractAlpha(mBlurPaint, outerBlurOffset);

    mBlurPaint.setMaskFilter(mThinOuterBlurMaskFilter);
    int[] brightOutlineOffset = new int[2];
    Bitmap brightOutline = srcDst.extractAlpha(mBlurPaint, brightOutlineOffset);

    // calculate the inner blur
    srcDstCanvas.setBitmap(srcDst);
    srcDstCanvas.drawColor(0xFF000000, PorterDuff.Mode.SRC_OUT);
    mBlurPaint.setMaskFilter(mMediumInnerBlurMaskFilter);
    int[] thickInnerBlurOffset = new int[2];
    Bitmap thickInnerBlur = srcDst.extractAlpha(mBlurPaint, thickInnerBlurOffset);

    // mask out the inner blur
    srcDstCanvas.setBitmap(thickInnerBlur);
    srcDstCanvas.drawBitmap(srcDst, -thickInnerBlurOffset[0],
            -thickInnerBlurOffset[1], mErasePaint);
    srcDstCanvas.drawRect(0, 0, -thickInnerBlurOffset[0], thickInnerBlur.getHeight(),
            mErasePaint);
    srcDstCanvas.drawRect(0, 0, thickInnerBlur.getWidth(), -thickInnerBlurOffset[1],
            mErasePaint);

    // draw the inner and outer blur
    srcDstCanvas.setBitmap(srcDst);
    srcDstCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
    srcDstCanvas.drawBitmap(thickInnerBlur, thickInnerBlurOffset[0], thickInnerBlurOffset[1],
            mDrawPaint);
    srcDstCanvas.drawBitmap(thickOuterBlur, outerBlurOffset[0], outerBlurOffset[1],
            mDrawPaint);

    // draw the bright outline
    srcDstCanvas.drawBitmap(brightOutline, brightOutlineOffset[0], brightOutlineOffset[1],
            mDrawPaint);

    // cleanup
    srcDstCanvas.setBitmap(null);
    brightOutline.recycle();
    thickOuterBlur.recycle();
    thickInnerBlur.recycle();
}
 
Example 9
Project: FlickLauncher   File: HolographicOutlineHelper.java   View Source Code Vote up 4 votes
public void applyExpensiveOutlineWithBlur(Bitmap srcDst, Canvas srcDstCanvas,
        boolean clipAlpha) {
    if (ProviderConfig.IS_DOGFOOD_BUILD && srcDst.getConfig() != Bitmap.Config.ALPHA_8) {
        throw new RuntimeException("Outline blue is only supported on alpha bitmaps");
    }

    // We start by removing most of the alpha channel so as to ignore shadows, and
    // other types of partial transparency when defining the shape of the object
    if (clipAlpha) {
        byte[] pixels = new byte[srcDst.getWidth() * srcDst.getHeight()];
        ByteBuffer buffer = ByteBuffer.wrap(pixels);
        buffer.rewind();
        srcDst.copyPixelsToBuffer(buffer);

        for (int i = 0; i < pixels.length; i++) {
            if ((pixels[i] & 0xFF) < 188) {
                pixels[i] = 0;
            }
        }

        buffer.rewind();
        srcDst.copyPixelsFromBuffer(buffer);
    }

    // calculate the outer blur first
    mBlurPaint.setMaskFilter(mMediumOuterBlurMaskFilter);
    int[] outerBlurOffset = new int[2];
    Bitmap thickOuterBlur = srcDst.extractAlpha(mBlurPaint, outerBlurOffset);

    mBlurPaint.setMaskFilter(mThinOuterBlurMaskFilter);
    int[] brightOutlineOffset = new int[2];
    Bitmap brightOutline = srcDst.extractAlpha(mBlurPaint, brightOutlineOffset);

    // calculate the inner blur
    srcDstCanvas.setBitmap(srcDst);
    srcDstCanvas.drawColor(0xFF000000, PorterDuff.Mode.SRC_OUT);
    mBlurPaint.setMaskFilter(mMediumInnerBlurMaskFilter);
    int[] thickInnerBlurOffset = new int[2];
    Bitmap thickInnerBlur = srcDst.extractAlpha(mBlurPaint, thickInnerBlurOffset);

    // mask out the inner blur
    srcDstCanvas.setBitmap(thickInnerBlur);
    srcDstCanvas.drawBitmap(srcDst, -thickInnerBlurOffset[0],
            -thickInnerBlurOffset[1], mErasePaint);
    srcDstCanvas.drawRect(0, 0, -thickInnerBlurOffset[0], thickInnerBlur.getHeight(),
            mErasePaint);
    srcDstCanvas.drawRect(0, 0, thickInnerBlur.getWidth(), -thickInnerBlurOffset[1],
            mErasePaint);

    // draw the inner and outer blur
    srcDstCanvas.setBitmap(srcDst);
    srcDstCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
    srcDstCanvas.drawBitmap(thickInnerBlur, thickInnerBlurOffset[0], thickInnerBlurOffset[1],
            mDrawPaint);
    srcDstCanvas.drawBitmap(thickOuterBlur, outerBlurOffset[0], outerBlurOffset[1],
            mDrawPaint);

    // draw the bright outline
    srcDstCanvas.drawBitmap(brightOutline, brightOutlineOffset[0], brightOutlineOffset[1],
            mDrawPaint);

    // cleanup
    srcDstCanvas.setBitmap(null);
    brightOutline.recycle();
    thickOuterBlur.recycle();
    thickInnerBlur.recycle();
}
 
Example 10
Project: SimpleUILauncher   File: HolographicOutlineHelper.java   View Source Code Vote up 4 votes
public void applyExpensiveOutlineWithBlur(Bitmap srcDst, Canvas srcDstCanvas,
        boolean clipAlpha) {
    if (ProviderConfig.IS_DOGFOOD_BUILD && srcDst.getConfig() != Bitmap.Config.ALPHA_8) {
        throw new RuntimeException("Outline blue is only supported on alpha bitmaps");
    }

    // We start by removing most of the alpha channel so as to ignore shadows, and
    // other types of partial transparency when defining the shape of the object
    if (clipAlpha) {
        byte[] pixels = new byte[srcDst.getWidth() * srcDst.getHeight()];
        ByteBuffer buffer = ByteBuffer.wrap(pixels);
        buffer.rewind();
        srcDst.copyPixelsToBuffer(buffer);

        for (int i = 0; i < pixels.length; i++) {
            if ((pixels[i] & 0xFF) < 188) {
                pixels[i] = 0;
            }
        }

        buffer.rewind();
        srcDst.copyPixelsFromBuffer(buffer);
    }

    // calculate the outer blur first
    mBlurPaint.setMaskFilter(mMediumOuterBlurMaskFilter);
    int[] outerBlurOffset = new int[2];
    Bitmap thickOuterBlur = srcDst.extractAlpha(mBlurPaint, outerBlurOffset);

    mBlurPaint.setMaskFilter(mThinOuterBlurMaskFilter);
    int[] brightOutlineOffset = new int[2];
    Bitmap brightOutline = srcDst.extractAlpha(mBlurPaint, brightOutlineOffset);

    // calculate the inner blur
    srcDstCanvas.setBitmap(srcDst);
    srcDstCanvas.drawColor(0xFF000000, PorterDuff.Mode.SRC_OUT);
    mBlurPaint.setMaskFilter(mMediumInnerBlurMaskFilter);
    int[] thickInnerBlurOffset = new int[2];
    Bitmap thickInnerBlur = srcDst.extractAlpha(mBlurPaint, thickInnerBlurOffset);

    // mask out the inner blur
    srcDstCanvas.setBitmap(thickInnerBlur);
    srcDstCanvas.drawBitmap(srcDst, -thickInnerBlurOffset[0],
            -thickInnerBlurOffset[1], mErasePaint);
    srcDstCanvas.drawRect(0, 0, -thickInnerBlurOffset[0], thickInnerBlur.getHeight(),
            mErasePaint);
    srcDstCanvas.drawRect(0, 0, thickInnerBlur.getWidth(), -thickInnerBlurOffset[1],
            mErasePaint);

    // draw the inner and outer blur
    srcDstCanvas.setBitmap(srcDst);
    srcDstCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
    srcDstCanvas.drawBitmap(thickInnerBlur, thickInnerBlurOffset[0], thickInnerBlurOffset[1],
            mDrawPaint);
    srcDstCanvas.drawBitmap(thickOuterBlur, outerBlurOffset[0], outerBlurOffset[1],
            mDrawPaint);

    // draw the bright outline
    srcDstCanvas.drawBitmap(brightOutline, brightOutlineOffset[0], brightOutlineOffset[1],
            mDrawPaint);

    // cleanup
    srcDstCanvas.setBitmap(null);
    brightOutline.recycle();
    thickOuterBlur.recycle();
    thickInnerBlur.recycle();
}
 
Example 11
Project: GitHub   File: ImageUtils.java   View Source Code Vote up 3 votes
/**
 * 转为alpha位图
 *
 * @param src     源图片
 * @param recycle 是否回收
 * @return alpha位图
 */
public static Bitmap toAlpha(final Bitmap src, final Boolean recycle) {
    if (isEmptyBitmap(src)) return null;
    Bitmap ret = src.extractAlpha();
    if (recycle && !src.isRecycled()) src.recycle();
    return ret;
}
 
Example 12
Project: Android-UtilCode   File: ImageUtils.java   View Source Code Vote up 3 votes
/**
 * 转为alpha位图
 *
 * @param src     源图片
 * @param recycle 是否回收
 * @return alpha位图
 */
public static Bitmap toAlpha(Bitmap src, Boolean recycle) {
    if (isEmptyBitmap(src)) return null;
    Bitmap ret = src.extractAlpha();
    if (recycle && !src.isRecycled()) src.recycle();
    return ret;
}
 
Example 13
Project: AndroidUtilCode-master   File: ImageUtils.java   View Source Code Vote up 3 votes
/**
 * 转为alpha位图
 *
 * @param src     源图片
 * @param recycle 是否回收
 * @return alpha位图
 */
public static Bitmap toAlpha(Bitmap src, Boolean recycle) {
    if (isEmptyBitmap(src)) return null;
    Bitmap ret = src.extractAlpha();
    if (recycle && !src.isRecycled()) src.recycle();
    return ret;
}
 
Example 14
Project: BaseCore   File: ImageUtils.java   View Source Code Vote up 3 votes
/**
 * 转为alpha位图
 *
 * @param src     源图片
 * @param recycle 是否回收
 * @return alpha位图
 */
public static Bitmap toAlpha(Bitmap src, Boolean recycle) {
    if (isEmptyBitmap(src)) return null;
    Bitmap ret = src.extractAlpha();
    if (recycle && !src.isRecycled()) src.recycle();
    return ret;
}
 
Example 15
Project: HeadlineNews   File: ImageUtils.java   View Source Code Vote up 3 votes
/**
 * 转为alpha位图
 *
 * @param src     源图片
 * @param recycle 是否回收
 * @return alpha位图
 */
public static Bitmap toAlpha(final Bitmap src, final Boolean recycle) {
    if (isEmptyBitmap(src)) return null;
    Bitmap ret = src.extractAlpha();
    if (recycle && !src.isRecycled()) src.recycle();
    return ret;
}
 
Example 16
Project: RLibrary   File: ImageUtils.java   View Source Code Vote up 3 votes
/**
 * 转为alpha位图
 *
 * @param src     源图片
 * @param recycle 是否回收
 * @return alpha位图
 */
public static Bitmap toAlpha(Bitmap src, Boolean recycle) {
    if (isEmptyBitmap(src)) return null;
    Bitmap ret = src.extractAlpha();
    if (recycle && !src.isRecycled()) src.recycle();
    return ret;
}
 
Example 17
Project: RLibrary   File: ImageUtils.java   View Source Code Vote up 3 votes
/**
 * 转为alpha位图
 *
 * @param src     源图片
 * @param recycle 是否回收
 * @return alpha位图
 */
public static Bitmap toAlpha(Bitmap src, Boolean recycle) {
    if (isEmptyBitmap(src)) return null;
    Bitmap ret = src.extractAlpha();
    if (recycle && !src.isRecycled()) src.recycle();
    return ret;
}