创建带着面具的ImageView的 [英] Creating an ImageView with a mask

查看:123
本文介绍了创建带着面具的ImageView的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我也跟着上XferModes对主题的一些其他问题,也API演示,并试图创建口罩根据alpha掩码其内容的ImageView的。
阿尔法位图包含了要显示的区域0阿尔法区域进行隐藏和255阿尔法。

I followed some other questions on the topic, and also API demos on XferModes, and attempted to create an ImageView that masks its content according to an alpha mask. The alpha bitmap contains 0 alpha for areas to be hidden and 255 alpha for areas to be shown.

这是的onDraw code:

This is the onDraw code:

@Override
protected void onDraw(Canvas canvas)
{
    super.onDraw(canvas);

    Paint paint = new Paint();
    paint.setFilterBitmap(false);
    paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));

    canvas.drawBitmap(mMaskBitmap, 0, 0, paint);
    paint.setXfermode(null);

它不为我工作。如果我把SRC_IN,面具只是获取绘制在上面。如果我把DST IN,我刚才看到原始图像。

It doesn't work for me. If I put SRC_IN, the mask just gets drawn on top. If I put DST IN, I just see the original image.

任何意见?

推荐答案

这个问题解决了,我发现的ImageView和掩码位图的尺寸为4像素的差异,这导致了整个事情默默故障...奇怪,没有抛出异常。

The problem was solved, I discovered that the ImageView and the mask bitmap's size had a difference of 4 pixels, which caused the whole thing to silently malfunction... Weird that there was no exception thrown.

总之,上述code ++工程,提供的掩码大小和LT; =的ImageView的大小

Anyway, the above code works, provided that the mask size <= the ImageView size.

这篇关于创建带着面具的ImageView的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆