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

The following examples show how to use android.graphics.Bitmap#extractAlpha() . 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: KcaViewButtonService.java    From kcanotify_h5-master with GNU General Public License v3.0 6 votes vote down vote up
private void setFairyImage() {
    boolean glow_available = fairy_glow_on && getBooleanPreferences(getApplicationContext(), PREF_KCA_NOTI_QUEST_FAIRY_GLOW);
    Bitmap src = KcaUtils.getFairyImageFromStorage(getApplicationContext(), viewBitmapId, dbHelper);
    Bitmap alpha = src.extractAlpha();
    Bitmap bmp = Bitmap.createBitmap(src.getWidth() + margin,
            src.getHeight() + margin, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bmp);
    if (glow_available) {
        Paint glow_paint = new Paint();
        glow_paint.setColor(glowColor);
        glow_paint.setMaskFilter(new BlurMaskFilter(glowRadius, BlurMaskFilter.Blur.OUTER));
        canvas.drawBitmap(alpha, halfMargin, halfMargin, glow_paint);
    }
    Paint color_paint = new Paint();
    if (taiha_status) {
        color_paint.setColorFilter(new PorterDuffColorFilter(ContextCompat.getColor(getApplicationContext(),
                R.color.colorHeavyDmgStateWarn), PorterDuff.Mode.MULTIPLY));
    } else if (glow_available) {
        color_paint.setColorFilter(new PorterDuffColorFilter(glowColor2, PorterDuff.Mode.MULTIPLY));
    }
    canvas.drawBitmap(src, halfMargin, halfMargin, color_paint);
    viewbutton.setImageBitmap(bmp);
}
 
Example 2
Source File: ShadowGenerator.java    From LaunchEnr with GNU General Public License v3.0 6 votes vote down vote up
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 3
Source File: ImageTools.java    From android-tv-launcher with 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 4
Source File: RxImageTool.java    From RxTools-master with Apache License 2.0 6 votes vote down vote up
/**
 * 可以对该图的非透明区域着色
 * <p>
 * 有多种使用场景,常见如 Button 的 pressed 状态,View 的阴影状态等
 *
 * @param iv
 * @param src
 * @param radius
 * @param color
 * @return
 */
private static Bitmap getDropShadow(ImageView iv, Bitmap src, float radius, int color) {

    final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(color);

    final int width = src.getWidth(), height = src.getHeight();
    final Bitmap dest = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(dest);
    final Bitmap alpha = src.extractAlpha();
    canvas.drawBitmap(alpha, 0, 0, paint);

    final BlurMaskFilter filter = new BlurMaskFilter(radius, BlurMaskFilter.Blur.OUTER);
    paint.setMaskFilter(filter);
    canvas.drawBitmap(alpha, 0, 0, paint);
    iv.setImageBitmap(dest);

    return dest;
}
 
Example 5
Source File: BitmapUtils.java    From Android-Next with Apache License 2.0 6 votes vote down vote up
/**
 *  为指定图片增加阴影
 *
 * @param map     图片
 * @param radius  阴影的半径
 * @return
 */
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(Config.ARGB_8888, true);
    Canvas c = new Canvas(shadowImage);
    c.drawBitmap(map, -offsetXY[0], -offsetXY[1], null);
    return shadowImage;
}
 
Example 6
Source File: ViewUtils.java    From HHComicViewer with Apache License 2.0 6 votes vote down vote up
public static Bitmap getAlphaBitmap(Bitmap mBitmap, int mColor) {
//          BitmapDrawable mBitmapDrawable = (BitmapDrawable) mContext.getResources().getDrawable(R.drawable.enemy_infantry_ninja);
//          Bitmap mBitmap = mBitmapDrawable.getBitmap();

        //BitmapDrawable的getIntrinsicWidth()方法,Bitmap的getWidth()方法
        //注意这两个方法的区别
        //Bitmap mAlphaBitmap = Bitmap.createBitmap(mBitmapDrawable.getIntrinsicWidth(), mBitmapDrawable.getIntrinsicHeight(), Config.ARGB_8888);
        Bitmap mAlphaBitmap = Bitmap.createBitmap(mBitmap.getWidth(), mBitmap.getHeight(), Bitmap.Config.ARGB_8888);

        Canvas mCanvas = new Canvas(mAlphaBitmap);
        Paint mPaint = new Paint();

        mPaint.setColor(mColor);
        //从原位图中提取只包含alpha的位图
        Bitmap alphaBitmap = mBitmap.extractAlpha();
        //在画布上(mAlphaBitmap)绘制alpha位图
        mCanvas.drawBitmap(alphaBitmap, 0, 0, mPaint);

        return mAlphaBitmap;
    }
 
Example 7
Source File: KcaViewButtonService.java    From kcanotify with GNU General Public License v3.0 6 votes vote down vote up
private void setFairyImage() {
    boolean glow_available = fairy_glow_on && getBooleanPreferences(getApplicationContext(), PREF_KCA_NOTI_QUEST_FAIRY_GLOW);
    Bitmap src = KcaUtils.getFairyImageFromStorage(getApplicationContext(), viewBitmapId, dbHelper);
    Bitmap alpha = src.extractAlpha();
    Bitmap bmp = Bitmap.createBitmap(src.getWidth() + margin,
            src.getHeight() + margin, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bmp);
    if (glow_available) {
        Paint glow_paint = new Paint();
        glow_paint.setColor(glowColor);
        glow_paint.setMaskFilter(new BlurMaskFilter(glowRadius, BlurMaskFilter.Blur.OUTER));
        canvas.drawBitmap(alpha, halfMargin, halfMargin, glow_paint);
    }
    Paint color_paint = new Paint();
    if (taiha_status) {
        color_paint.setColorFilter(new PorterDuffColorFilter(ContextCompat.getColor(getApplicationContext(),
                R.color.colorHeavyDmgStateWarn), PorterDuff.Mode.MULTIPLY));
    } else if (glow_available) {
        color_paint.setColorFilter(new PorterDuffColorFilter(glowColor2, PorterDuff.Mode.MULTIPLY));
    }
    canvas.drawBitmap(src, halfMargin, halfMargin, color_paint);
    viewbutton.setImageBitmap(bmp);
}
 
Example 8
Source File: StackView.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
void drawOutline(Canvas dest, Bitmap src) {
    final int[] xy = mTmpXY;
    Bitmap mask = src.extractAlpha(mBlurPaint, xy);
    mMaskCanvas.setBitmap(mask);
    mMaskCanvas.drawBitmap(src, -xy[0], -xy[1], mErasePaint);
    dest.drawColor(0, PorterDuff.Mode.CLEAR);
    dest.setMatrix(mIdentityMatrix);
    dest.drawBitmap(mask, xy[0], xy[1], mHolographicPaint);
    mMaskCanvas.setBitmap(null);
    mask.recycle();
}
 
Example 9
Source File: JPEGFactory.java    From PdfBox-Android with Apache License 2.0 5 votes vote down vote up
private static Bitmap getAlphaImage(Bitmap image) throws IOException
{
    if (!image.hasAlpha())
    {
        return null;
    }
    return image.extractAlpha();
}
 
Example 10
Source File: HolographicOutlineHelper.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
Bitmap createMediumDropShadow(BubbleTextView view) {
    Drawable icon = view.getIcon();
    if (icon == null) {
        return null;
    }
    Rect rect = icon.getBounds();

    int bitmapWidth = (int) (rect.width() * view.getScaleX());
    int bitmapHeight = (int) (rect.height() * view.getScaleY());

    if (bitmapWidth == 0 || bitmapHeight == 0) {
        return null;
    }

    int key = (bitmapWidth << 16) | bitmapHeight;
    Bitmap cache = mBitmapCache.get(key);
    if (cache == null) {
        cache = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Bitmap.Config.ARGB_8888);
        mCanvas.setBitmap(cache);
        mBitmapCache.put(key, cache);
    } else {
        mCanvas.setBitmap(cache);
        mCanvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
    }

    mCanvas.save(Canvas.MATRIX_SAVE_FLAG);
    mCanvas.scale(view.getScaleX(), view.getScaleY());
    mCanvas.translate(-rect.left, -rect.top);
    icon.draw(mCanvas);
    mCanvas.restore();
    mCanvas.setBitmap(null);

    mBlurPaint.setMaskFilter(mShadowBlurMaskFilter);
    return cache.extractAlpha(mBlurPaint, null);
}
 
Example 11
Source File: ImageUtils.java    From Android-utils with Apache License 2.0 4 votes vote down vote up
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
Source File: HolographicOutlineHelper.java    From LB-Launcher with Apache License 2.0 4 votes vote down vote up
Bitmap createMediumDropShadow(BubbleTextView view) {
    final Bitmap result = Bitmap.createBitmap(
            view.getWidth() + shadowBitmapPadding + shadowBitmapPadding,
            view.getHeight() + shadowBitmapPadding + shadowBitmapPadding + mShadowOffset,
            Bitmap.Config.ARGB_8888);

    mCanvas.setBitmap(result);

    final Rect clipRect = sTempRect;
    view.getDrawingRect(sTempRect);
    // adjust the clip rect so that we don't include the text label
    clipRect.bottom = view.getExtendedPaddingTop() - (int) BubbleTextView.PADDING_V
            + view.getLayout().getLineTop(0);

    // Draw the View into the bitmap.
    // The translate of scrollX and scrollY is necessary when drawing TextViews, because
    // they set scrollX and scrollY to large values to achieve centered text
    mCanvas.save();
    mCanvas.scale(view.getScaleX(), view.getScaleY(),
            view.getWidth() / 2 + shadowBitmapPadding,
            view.getHeight() / 2 + shadowBitmapPadding);
    mCanvas.translate(-view.getScrollX() + shadowBitmapPadding,
            -view.getScrollY() + shadowBitmapPadding);
    mCanvas.clipRect(clipRect, Op.REPLACE);
    view.draw(mCanvas);
    mCanvas.restore();

    int[] blurOffst = new int[2];
    mBlurPaint.setMaskFilter(mShaowBlurMaskFilter);
    Bitmap blurBitmap = result.extractAlpha(mBlurPaint, blurOffst);

    mCanvas.save();
    mCanvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
    mCanvas.translate(blurOffst[0], blurOffst[1]);

    mDrawPaint.setColor(Color.BLACK);
    mDrawPaint.setAlpha(30);
    mCanvas.drawBitmap(blurBitmap, 0, 0, mDrawPaint);

    mDrawPaint.setAlpha(60);
    mCanvas.drawBitmap(blurBitmap, 0, mShadowOffset, mDrawPaint);
    mCanvas.restore();

    mCanvas.setBitmap(null);
    blurBitmap.recycle();

    return result;
}
 
Example 13
Source File: HolographicOutlineHelper.java    From LB-Launcher with Apache License 2.0 4 votes vote down vote up
void applyExpensiveOutlineWithBlur(Bitmap srcDst, Canvas srcDstCanvas, int color,
        int outlineColor, boolean clipAlpha) {

    // 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) {
        int[] srcBuffer = new int[srcDst.getWidth() * srcDst.getHeight()];
        srcDst.getPixels(srcBuffer,
                0, srcDst.getWidth(), 0, 0, srcDst.getWidth(), srcDst.getHeight());
        for (int i = 0; i < srcBuffer.length; i++) {
            final int alpha = srcBuffer[i] >>> 24;
            if (alpha < 188) {
                srcBuffer[i] = 0;
            }
        }
        srcDst.setPixels(srcBuffer,
                0, srcDst.getWidth(), 0, 0, srcDst.getWidth(), srcDst.getHeight());
    }
    Bitmap glowShape = srcDst.extractAlpha();

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

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

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

    // mask out the inner blur
    srcDstCanvas.setBitmap(thickInnerBlur);
    srcDstCanvas.drawBitmap(glowShape, -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);
    mDrawPaint.setColor(color);
    srcDstCanvas.drawBitmap(thickInnerBlur, thickInnerBlurOffset[0], thickInnerBlurOffset[1],
            mDrawPaint);
    srcDstCanvas.drawBitmap(thickOuterBlur, outerBlurOffset[0], outerBlurOffset[1],
            mDrawPaint);

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

    // cleanup
    srcDstCanvas.setBitmap(null);
    brightOutline.recycle();
    thickOuterBlur.recycle();
    thickInnerBlur.recycle();
    glowShape.recycle();
}
 
Example 14
Source File: HolographicOutlineHelper.java    From Trebuchet with GNU General Public License v3.0 4 votes vote down vote up
void applyExpensiveOutlineWithBlur(Bitmap srcDst, Canvas srcDstCanvas, int color,
        int outlineColor, boolean clipAlpha) {

    // 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) {
        int[] srcBuffer = new int[srcDst.getWidth() * srcDst.getHeight()];
        srcDst.getPixels(srcBuffer,
                0, srcDst.getWidth(), 0, 0, srcDst.getWidth(), srcDst.getHeight());
        for (int i = 0; i < srcBuffer.length; i++) {
            final int alpha = srcBuffer[i] >>> 24;
            if (alpha < 188) {
                srcBuffer[i] = 0;
            }
        }
        srcDst.setPixels(srcBuffer,
                0, srcDst.getWidth(), 0, 0, srcDst.getWidth(), srcDst.getHeight());
    }
    Bitmap glowShape = srcDst.extractAlpha();

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

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

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

    // mask out the inner blur
    srcDstCanvas.setBitmap(thickInnerBlur);
    srcDstCanvas.drawBitmap(glowShape, -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);
    mDrawPaint.setColor(color);
    srcDstCanvas.drawBitmap(thickInnerBlur, thickInnerBlurOffset[0], thickInnerBlurOffset[1],
            mDrawPaint);
    srcDstCanvas.drawBitmap(thickOuterBlur, outerBlurOffset[0], outerBlurOffset[1],
            mDrawPaint);

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

    // cleanup
    srcDstCanvas.setBitmap(null);
    brightOutline.recycle();
    thickOuterBlur.recycle();
    thickInnerBlur.recycle();
    glowShape.recycle();
}
 
Example 15
Source File: HolographicOutlineHelper.java    From LaunchEnr with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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 16
Source File: ImageUtils.java    From AndroidUtilCode with Apache License 2.0 3 votes vote down vote up
/**
 * Return the alpha bitmap.
 *
 * @param src     The source of bitmap.
 * @param recycle True to recycle the source of bitmap, false otherwise.
 * @return the alpha bitmap
 */
public static Bitmap toAlpha(final Bitmap src, final Boolean recycle) {
    if (isEmptyBitmap(src)) return null;
    Bitmap ret = src.extractAlpha();
    if (recycle && !src.isRecycled() && ret != src) src.recycle();
    return ret;
}
 
Example 17
Source File: RxImageTool.java    From RxTools-master with Apache License 2.0 3 votes vote down vote up
/**
 * 转为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 18
Source File: ImageUtils.java    From Android-UtilCode with Apache License 2.0 3 votes vote down vote up
/**
 * 转为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 19
Source File: BitmapUtils.java    From FastAndroid with Apache License 2.0 2 votes vote down vote up
/**
 * 转为 alpha 位图
 *
 * @param src     源图片
 * @param recycle 是否回收
 * @return alpha 位图
 */
public static Bitmap toAlpha(@NonNull Bitmap src, Boolean recycle) {
    Bitmap ret = src.extractAlpha();
    if (recycle && !src.isRecycled()) src.recycle();
    return ret;
}
 
Example 20
Source File: BitmapUtils.java    From DevUtils with Apache License 2.0 2 votes vote down vote up
/**
 * 获取 Alpha 位图 ( 获取源图片的轮廓 rgb 为 0)
 * @param bitmap {@link Bitmap}
 * @return Alpha 位图
 */
public static Bitmap extractAlpha(final Bitmap bitmap) {
    if (isEmpty(bitmap)) return null;
    return bitmap.extractAlpha();
}