示例#1
0
        private static Bitmap ApplyTransform(this Bitmap source, Bitmap destination, Func <byte, byte, byte> transformFunction)
        {
            if (source == null || destination == null)
            {
                return(null);
            }

            var fastSource      = new UnsafeBitmap(source);
            var fastDestination = new UnsafeBitmap(destination);

            fastSource.LockBitmap();
            fastDestination.LockBitmap();

            for (int i = 0; i < source.Height; i++)
            {
                for (int j = 0; j < source.Width; j++)
                {
                    var sourcePixel      = fastSource.GetPixel(j, i);
                    var destinationPixel = fastDestination.GetPixel(j, i);

                    var diffPixel = new PixelData
                    {
                        red   = transformFunction.Invoke(destinationPixel.red, sourcePixel.red),
                        green = transformFunction.Invoke(destinationPixel.green, sourcePixel.green),
                        blue  = transformFunction.Invoke(destinationPixel.blue, sourcePixel.blue),
                    };

                    fastDestination.SetPixel(j, i, diffPixel);
                }
            }

            fastSource.UnlockBitmap();
            fastDestination.UnlockBitmap();

            return(fastDestination.Bitmap);
        }
示例#2
0
        public void SetPixel(int x, int y, PixelData colour)
        {
            PixelData *pixel = PixelAt(x, y);

            *pixel = colour;
        }
示例#3
0
        public PixelData GetPixel(int x, int y)
        {
            PixelData returnValue = *PixelAt(x, y);

            return(returnValue);
        }