AlbLib.Imaging.TransparencyTable.GetResultingColorIndex C# (CSharp) Метод

GetResultingColorIndex() публичный Метод

Gets resulting color when blending two others.
public GetResultingColorIndex ( byte overlaying, byte underlaying, TransparencyType type ) : byte
overlaying byte /// Foreground color. ///
underlaying byte /// Background color. ///
type TransparencyType /// Type of blending. ///
Результат byte
        public byte GetResultingColorIndex(byte overlaying, byte underlaying, TransparencyType type)
        {
            switch(type)
            {
                case TransparencyType.None:
                    return overlaying;
                case TransparencyType.Dark:
                    return dark[underlaying*256+overlaying];
                case TransparencyType.Main:
                    return main[underlaying*256+overlaying];
                case TransparencyType.Light:
                    return light[underlaying*256+overlaying];
                default:
                    throw new ArgumentException("Unknown type.", "type");
            }
        }

Usage Example

Пример #1
0
        private void ApplyBake(byte[] tobake)
        {
            int width  = Background.GetWidth();
            int height = Background.GetHeight();
            TransparencyTable trans = TransparencyTable;

            foreach (GraphicObject obj in Objects)
            {
                if (obj == null || obj.Image == null)
                {
                    continue;
                }
                for (int y = 0; y < obj.Image.GetHeight(); y++)
                {
                    for (int x = 0; x < obj.Image.GetWidth(); x++)
                    {
                        if (x + obj.Location.X >= 0 && y + obj.Location.Y >= 0 && x + obj.Location.X < width && y + obj.Location.Y < height)
                        {
                            byte color = obj.Image.ImageData[obj.Image.GetWidth() * y + x];
                            if (color == obj.TransparentIndex)
                            {
                                continue;
                            }
                            int index = width * (y + obj.Location.Y) + obj.Location.X + x;
                            if (trans == null || obj.Transparency == TransparencyType.None)
                            {
                                tobake[index] = color;
                            }
                            else
                            {
                                tobake[index] = trans.GetResultingColorIndex(color, tobake[index], obj.Transparency);
                            }
                        }
                    }
                }
            }
        }