Exemple #1
0
        public static void Compose(PorterDuffCompositingMode mode, Bitmap source, Bitmap destination)
        {
            var minWidth  = Math.Min(source.Width, destination.Width);
            var minHeight = Math.Min(source.Height, destination.Height);

#if false
            for (int y = 0; y < minHeight; ++y)
            {
                for (int x = 0; x < minWidth; ++x)
                {
                    var tmp = mode.ComposePixel(source.GetPixel(x, y), destination.GetPixel(x, y));
                    destination.SetPixel(x, y, tmp);
                }
            }
#else
            var rect = new Rectangle(0, 0, minWidth, minHeight);
            using (var sourceData = PixelData.LockBits(source, rect, ImageLockMode.ReadOnly))
                using (var destinationData = PixelData.LockBits(destination, rect, ImageLockMode.ReadWrite))
                {
                    for (int y = 0; y < minHeight; ++y)
                    {
                        var destYOffset = y * destinationData.Stride;
                        var destXOffset = y * sourceData.Stride;

                        for (int x = 0; x < minWidth; ++x)
                        {
                            int destIndex = destYOffset + x;
                            int srcIndex  = destXOffset + x;

                            Color destColor = Color.FromArgb(destinationData.Bytes[destIndex]);
                            Color srcColor  = Color.FromArgb(sourceData.Bytes[srcIndex]);

                            destinationData.Bytes[destIndex] = mode.ComposePixel(srcColor, destColor).ToArgb();
                        }
                    }

                    destinationData.Commit();
                }
#endif
        }
Exemple #2
0
 public CompositingModeComboBoxItem(string name, PorterDuffCompositingMode mode)
 {
     this.Name = name;
     this.Mode = mode;
 }