Exemplo n.º 1
0
        public BitmapSource Create()
        {
            this.EditableBitmap = new EditableBitmap(Width, Height, 0xff, 0xff, 0, 0xaa);
            //return this.EditableBitmap.RenderBitmap();

            var _Sensors = new List<IPixelValuePair<Double, Byte>>();
            _Sensors.Add(new PixelValuePair<Double, Byte>(32,  64,  128));
            _Sensors.Add(new PixelValuePair<Double, Byte>(128, 128, 255));

            Pixel<Double> Pixel = null;
            var Distance = new ThreadLocal<Double>();
            var Force    = new ThreadLocal<Double>();
            var Force2   = new ThreadLocal<Double>();
            Int32 n = _Sensors.Count;

            Parallel.For(0, Width, (_sx) =>
            {
                for (var _sy = 0; _sy < Height; _sy++)
                {

                    Force.Value = 0.0;

                    foreach (var _Sensor in _Sensors)
                    {
                        Distance.Value = _Sensor.DistanceTo(_sx, _sy);
                        if (Distance.Value == 0)
                            Force.Value += _Sensor.Value;
                        else
                            Force.Value += n * _Sensor.Value / Distance.Value;
                    }

                    if (Force.Value <= 255 * n)
                        Force2.Value = (255 * n - Force.Value) / n;
                    else
                        Force2.Value = 255;

                    if (Force2.Value < 0)
                    {
                        var ab = 1;
                        ab = 2;
                    }

                    if (Force2.Value > 255)
                    {
                        var ac = 1;
                        ac = 2;
                    }

                    this.EditableBitmap.PutPixel(_sx, _sy, (Byte) Force2.Value, 0xaa);

                }
            });

            return this.EditableBitmap.RenderBitmap();

            //var _Image2 = new Image();
            //_Image2.Stretch = Stretch.Uniform;
            //_Image2.Source = Pic;
            //_Image2.Width = Pic.PixelWidth;
        }
Exemplo n.º 2
0
        public BitmapSource Create()
        {
            this.EditableBitmap = new EditableBitmap(Width, Height, 0xff, 0xff, 0, 0xaa);
            //return this.EditableBitmap.RenderBitmap();

            var _Sensors = new List <IPixelValuePair <Double, Byte> >();

            _Sensors.Add(new PixelValuePair <Double, Byte>(32, 64, 128));
            _Sensors.Add(new PixelValuePair <Double, Byte>(128, 128, 255));

            Pixel <Double> Pixel    = null;
            var            Distance = new ThreadLocal <Double>();
            var            Force    = new ThreadLocal <Double>();
            var            Force2   = new ThreadLocal <Double>();
            Int32          n        = _Sensors.Count;

            Parallel.For(0, Width, (_sx) =>
            {
                for (var _sy = 0; _sy < Height; _sy++)
                {
                    Force.Value = 0.0;

                    foreach (var _Sensor in _Sensors)
                    {
                        Distance.Value = _Sensor.DistanceTo(_sx, _sy);
                        if (Distance.Value == 0)
                        {
                            Force.Value += _Sensor.Value;
                        }
                        else
                        {
                            Force.Value += n * _Sensor.Value / Distance.Value;
                        }
                    }

                    if (Force.Value <= 255 * n)
                    {
                        Force2.Value = (255 * n - Force.Value) / n;
                    }
                    else
                    {
                        Force2.Value = 255;
                    }

                    if (Force2.Value < 0)
                    {
                        var ab = 1;
                        ab     = 2;
                    }

                    if (Force2.Value > 255)
                    {
                        var ac = 1;
                        ac     = 2;
                    }

                    this.EditableBitmap.PutPixel(_sx, _sy, (Byte)Force2.Value, 0xaa);
                }
            });

            return(this.EditableBitmap.RenderBitmap());

            //var _Image2 = new Image();
            //_Image2.Stretch = Stretch.Uniform;
            //_Image2.Source = Pic;
            //_Image2.Width = Pic.PixelWidth;
        }