在Android中填充透明色的画布

时间:2013-11-26 11:42:49

标签: android colors imageview transparency android-canvas

早上好,

我有ImageView我用#99aaaaaa颜色初始化(它对应于153,170,170,170)。之后我画了一些不同颜色的线条。现在我想用原始颜色填充我的画布(#99aaaaaa)

方法myCanvas.drawColor(OriginalColor)用OriginalColor填充画布,但线条仍然可见

    myPaint.setColor(OriginalColor);
    myPaint.setStyle(Paint.Style.FILL);
    myCanvas.drawRect(0, 0, 170, 170, myPaint); // my ImageView is  170X170

也让线条可见。

请帮助,谢谢

2 个答案:

答案 0 :(得分:1)

因为画布原始颜色是半透明的,然后你在上面绘制一些东西并绘制另一层半透明的东西,然后很明显你会看到顶层的水平向下透明层不是吗?换句话说,如果你在膝盖上放一个半透明的玻璃杯,你还会看到膝盖穿过它

答案 1 :(得分:0)

在调用drawRec()之前,如下设置传输模式:

using System;
using Autofac;
using Autofac.Features.AttributeFilters;

public class Program
{
    public interface IHello
    {
         string Greetings { get; }
    }

    public class Hello : IHello
    {
        public string Greetings
        {
            get;
            set;
        }
    }

    public class HelloConsumer
    {
        public HelloConsumer([KeyFilter("EN")] IHello hello)
        {
            Console.WriteLine(hello.Greetings);
        }
    }

    public static void Main()
    {
        ContainerBuilder cb = new ContainerBuilder();
        cb.RegisterType<HelloConsumer>().AsSelf().WithAttributeFiltering();
        var helloEn = new Hello { Greetings = "Hi" };
        var helloFr = new Hello { Greetings = "Bonjour" };
        cb.Register<Hello>(x => helloEn).Keyed<IHello>("EN");
        cb.Register<Hello>(x => helloFr).Keyed<IHello>("FR");
        var container = cb.Build();

        container.Resolve<HelloConsumer>(); // Should write the correct greeting
    }
}

此后重置画家,以进行进一步绘制:

paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));