Exemplo n.º 1
0
        public void Run()
        {
            SharpDX.Threading.TaskUtil.Run(() =>
            {
                while (!_cancelTask.IsCancellationRequested)
                {
                    lock (_lockObj)
                    {
                        hwndRenderTarget.BeginDraw();
                        hwndRenderTarget.Clear(Color.White);

                        if (_opacity > 0.0f)//表示切换中
                        {
                            RectangleF preRenderRect = ZoomBitmap(RenderTargetClientSize, _preBmp.Size);
                            hwndRenderTarget.DrawBitmap(_preBmp.Bmp, preRenderRect, _opacity, BitmapInterpolationMode.NearestNeighbor, _preBmp.BitmapRectangleF);

                            _opacity -= 0.02f;
                        }
                        else
                        {
                            if (_preBmp != null)
                            {
                                _preBmp.Dispose();
                            }
                        }
                        RectangleF renderRect = ZoomBitmap(RenderTargetClientSize, _bmp.Size);
                        hwndRenderTarget.DrawBitmap(_bmp.Bmp, renderRect, 1f - _opacity, BitmapInterpolationMode.NearestNeighbor, _bmp.BitmapRectangleF);

                        hwndRenderTarget.EndDraw();
                    }
                    Thread.Sleep(40);
                }
            });
        }
Exemplo n.º 2
0
        // Dispose(bool disposing) executes in two distinct scenarios.
        // If disposing equals true, the method has been called directly
        // or indirectly by a user's code. Managed and unmanaged resources
        // can be disposed.
        // If disposing equals false, the method has been called by the
        // runtime from inside the finalizer and you should not reference
        // other objects. Only unmanaged resources can be disposed.
        protected virtual void Dispose(bool disposing)
        {
            // Check to see if Dispose has already been called.
            if (!this.disposed)
            {
                // If disposing equals true, dispose all managed
                // and unmanaged resources.
                if (disposing)
                {
                    // Dispose managed resources.

                    if (hwndRenderTarget != null)
                    {
                        hwndRenderTarget.Dispose();
                        hwndRenderTarget = null;
                    }
                    if (_preBmp != null)
                    {
                        _preBmp.Dispose();
                        _preBmp = null;
                    }

                    if (_bmp != null)
                    {
                        _bmp.Dispose();
                        _bmp = null;
                    }
                }

                // Call the appropriate methods to clean up
                // unmanaged resources here.
                // If disposing is false,
                // only the following code is executed.

                // Note disposing has been done.
                disposed = true;
            }
        }