Exemplo n.º 1
0
 public void SetImage(Image image)
 {
     _image     = MyPicture.create(image, Bounds);
     _nextImage = null;
     _transitionTimer.Enabled = _image.StartAnimate();
     Invalidate();
 }
Exemplo n.º 2
0
 public void TransitionImage(Image image, float transitionTime)
 {
     _nextImage = MyPicture.create(image, Bounds);
     _stopwatch = Stopwatch.StartNew();
     _transitionTimer.Enabled = true;
     this._transitionTime     = transitionTime;
     Invalidate();
 }
Exemplo n.º 3
0
        protected override void OnPaint(PaintEventArgs pe)
        {
            Graphics graphic = pe.Graphics;

            if (_nextImage != null)
            {
                var elapsedMilliseconds = _stopwatch.ElapsedMilliseconds;
                if (elapsedMilliseconds > _transitionTime)
                {
                    _image     = _nextImage;
                    _nextImage = null;
                    _transitionTimer.Enabled = _image.StartAnimate();
                    graphic.DrawImageUnscaled(_image.GetRenderedImage(), 0, 0);
                }
                else
                {
                    graphic.DrawImageUnscaled(_image.GetRenderedImage(), 0, 0);

                    var imageAttributes = new ImageAttributes();
                    imageAttributes.SetColorMatrix(new ColorMatrix {
                        Matrix33 = elapsedMilliseconds / _transitionTime
                    });
                    var renderedImage = _nextImage.GetRenderedImage();
                    var bounds        = new Rectangle(0, 0, renderedImage.Width, renderedImage.Height);
                    graphic.DrawImage(renderedImage, bounds, 0, 0, bounds.Width, bounds.Height, GraphicsUnit.Pixel,
                                      imageAttributes);
                }
            }
            else
            {
                graphic.DrawImageUnscaled(_image.GetRenderedImage(), 0, 0);
            }


            graphic.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;

            if (LowerLeftText != null)
            {
                DrawText(graphic, LowerLeftText, StringFormat.GenericDefault,
                         rect => new PointF(rect.X, Bounds.Height - rect.Height));
            }
            if (LowerMiddleText != null)
            {
                var stringFormat = new StringFormat(StringFormat.GenericDefault);
                stringFormat.LineAlignment = StringAlignment.Center;
                DrawText(graphic, LowerMiddleText, stringFormat,
                         rect => new PointF((Bounds.Width - rect.Width) / 2, Bounds.Height - rect.Height));
            }
            if (LowerRightText != null)
            {
                var stringFormat = new StringFormat(StringFormat.GenericDefault);
                stringFormat.LineAlignment = StringAlignment.Far;
                DrawText(graphic, LowerRightText, stringFormat,
                         rect => new PointF((Bounds.Width - rect.Width), Bounds.Height - rect.Height));
            }
        }