Android 如何使用alpha遮罩剪裁和填充画布

Android 如何使用alpha遮罩剪裁和填充画布,android,Android,我有一些.png图标是alpha遮罩。我需要使用Android SDK将它们渲染为可绘制图像 在iPhone上,我使用以下方法获得此结果,使用黑色作为填充将“图像”alpha遮罩转换为“图像遮罩”图像: CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGContextRef context = CGBitmapContextCreate(NULL, thumbWidth, thumbHeight, 8, 4*th

我有一些.png图标是alpha遮罩。我需要使用Android SDK将它们渲染为可绘制图像

在iPhone上,我使用以下方法获得此结果,使用黑色作为填充将“图像”alpha遮罩转换为“图像遮罩”图像:

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(NULL, thumbWidth, 
    thumbHeight, 8, 4*thumbWidth, colorSpace, kCGImageAlphaPremultipliedFirst);
CGRect frame = CGRectMake(0,0,thumbWidth,thumbHeight);
CGContextClipToMask(context, frame, [image CGImage]);
CGContextFillRect(context, frame);

CGImageRef imageMasked = CGBitmapContextCreateImage(context);
CGContextRelease(context);
如何在Android SDK中实现上述功能

我已经开始写以下内容:

Drawable image = myPngImage;

final int width = image.getMinimumWidth();
final int height = image.getMinimumHeight();

Bitmap imageMasked = Bitmap.createBitmap(width,
    height, Config.ARGB_8888);
Canvas canvas = new Canvas(iconMasked);
image.draw(canvas); ???
我找不到如何在使用图像屏蔽的图像上进行剪辑

已解决:

Drawable icon = An_Icon_That_Is_An_Alpha_Mask;
int width = icon.getIntrinsicWidth();
int height = icon.getIntrinsicHeight();
Bitmap bm = Bitmap.createBitmap(width, height, Bitmap.Config.ALPHA_8);
Canvas canvas = new Canvas(bm);
icon.setBounds(new Rect(0,0,width,height));
icon.draw(canvas);

我可能没有回答这个问题,但是如果你把带有alpha的图像分配给图像视图,alpha就会出现。我在这里要做的是将alpha位图转换成一个剪切区域,并使用它进行填充。基本上是应用阿尔法遮罩。还有其他人愿意回答吗?我想做的是这样的:final int width=icon.getMinimumWidth();最终整数高度=icon.getMinimumHeight();Bitmap iconMasked=Bitmap.createBitmap(宽度、高度、配置.ARGB_8888);Canvas Canvas=新画布(iconMasked);final Region=icon.getTransparentRegion();canvas.clipRegion(区域);drawARGB(255,0,0,0);这种方法的问题是我的图标从getTransparentRegion()返回null。没想到,所以我还在寻找答案。