/// <summary>
        /// Function to Create Gradient and save it as the current image.
        /// </summary>
        /// <param name="fileName">Path of the Image</param>
        public Bitmap Gradient(IEnergyCalculator energyCalculator)
        {
            _imgProcessor.Open();

            int[,] energy = _imgProcessor.Energy(energyCalculator,true);

            _imgProcessor.Close();

            return _imgProcessor.GetBmp();
        }
        // Breaki odtwarzajace bug

        /// <summary>
        /// Calculates gradient with or without saving to image
        /// </summary>
        /// <param name="saveBmp">Save to File</param>
        /// <returns>Array of Energies</returns>
        public int[,] Energy(IEnergyCalculator energyCalculator,bool changeBmp)
        {

            int[,] energy = new int[_bmp.Width, _bmp.Height];

            _current = (byte*)(void*)_bmd.Scan0;

            int nOffset = _bmd.Stride - _bmp.Width * _pixelSize;
            int nWidth = _bmp.Width * _pixelSize;
            int currentEnergy = 0;
            int ex = 0, ey = 0;
            // ostatni wiersz narazie pomijam 
            // bo jest problem z przekroczonym adresem jak dodam stride-a
            for (int y = 0; y < _bmp.Height; y++)
            {
                ex = 0;
                for (int x = 0; x < nWidth; x++)
                {
                    if (x % _pixelSize == 0 || x == 0)
                    {
                        if (y == _bmp.Height - 1)
                        {
                            currentEnergy = energyCalculator.CalculateEnergy((int)_current, _bmd, 1);
                        }
                        else
                        {
                            currentEnergy = energyCalculator.CalculateEnergy((int)_current, _bmd, 0);
                        }

                        if (changeBmp)
                            LibraryUnsafe.SetColor(currentEnergy, _current);

                            energy[ex, ey] = currentEnergy;    

                        ex++;
                    }
                    _current++;
                }
                _current += nOffset;
                ey++;
            }

            //energy[_bmp.Width-1, _bmp.Height-1] = 9999999;
            return energy;
        }