本文整理汇总了Java中android.graphics.Bitmap.extractAlpha方法的典型用法代码示例。如果您正苦于以下问题:Java Bitmap.extractAlpha方法的具体用法?Java Bitmap.extractAlpha怎么用?Java Bitmap.extractAlpha使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.graphics.Bitmap
的用法示例。
在下文中一共展示了Bitmap.extractAlpha方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: recreateIcon
import android.graphics.Bitmap; //导入方法依赖的package包/类
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;
}
示例2: drawImageDropShadow
import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
*图片阴影
* @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);
}
示例3: drawShadow
import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
* 为指定图片增加阴影
*
* @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;
}
示例4: toAlpha
import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
* 转为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;
}
示例5: toAlpha
import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
* 转为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;
}
示例6: applyExpensiveOutlineWithBlur
import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
* 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();
}
示例7: applyExpensiveOutlineWithBlur
import android.graphics.Bitmap; //导入方法依赖的package包/类
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();
}
示例8: toAlpha
import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
* 转为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;
}
示例9: toAlpha
import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
* 转为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;
}