示例#1
0
        public void SetBitmap(byte[] bitmapBytes)
        {
            _bitmapBytes          = bitmapBytes;
            _bitmapRepresentation = null;

            Draw();
        }
示例#2
0
 public LayoutDrawElement(Location location, BitmapEx bitmap, TransitionInfo transitionInfo = default(TransitionInfo))
 {
     Location             = location;
     TransitionInfo       = transitionInfo;
     BitmapRepresentation = new BitmapRepresentation(bitmap);
     bitmap.Dispose();
 }
示例#3
0
        public void TestBitmapResize()
        {
            Color green = Color.FromArgb(0, 200, 0);
            Color red   = Color.FromArgb(200, 0, 0);

            using (var bitmap = new Bitmap(20, 20))
            {
                using (var graphics = Graphics.FromImage(bitmap))
                    using (var gBrush = new SolidBrush(green))
                        using (var rBrush = new SolidBrush(red))
                        {
                            graphics.FillRectangle(gBrush, 0, 0, 10, 20);
                            graphics.FillRectangle(rBrush, 10, 0, 10, 20);
                        }

                using (var sourceRepresentation = new BitmapRepresentation(bitmap))
                    using (var sourceBitmapEx = sourceRepresentation.CreateBitmap())
                        using (var destinationBitmapEx = new BitmapEx(10, 10))
                        {
                            BitmapHelpers.ResizeBitmap(sourceBitmapEx, destinationBitmapEx);
                            var bmp = destinationBitmapEx.GetInternal();
                            {
                                var green2 = bmp.GetPixel(3, 5);
                                var red2   = bmp.GetPixel(7, 5);
                                Assert.AreEqual(true, CompareColors(green, green2, 5));
                                Assert.AreEqual(true, CompareColors(red, red2, 5));
                            }
                        }
            }
        }
示例#4
0
 protected override void OnEnteredLayout(LayoutContext layoutContext, ILayout previousLayout)
 {
     _individualButtonSize = CalculateIndividualButtonSize();
     _buttonShift          = CalculateButtonShift();
     using (var bitmap = layoutContext.CreateBitmap())
         _currentRepresentation = new BitmapRepresentation(bitmap);
     _layoutToManage.DrawLayout += OnDrawLayout;
     _layoutToManage.EnterLayout(layoutContext, _previousLayout);
 }
示例#5
0
        protected override void OnLeavingLayout()
        {
            foreach (IPlayerService playerService in _playerServices)
            {
                playerService.PlayingInfoChanged -= PlayerServiceOnPlayingInfoChanged;
            }

            _previousRepresentation = DefaultBitmapRepresentation;
        }
示例#6
0
        public VisualEffectInfo(Location location, IVisualTransition transition, BitmapRepresentation first, BitmapRepresentation last, int steps)
        {
            _location   = location;
            _transition = transition;
            _first      = first;
            _last       = last;

            transition.Init(first, last, steps);
        }
示例#7
0
 private BitmapRepresentation GetBitmapRepresentation(byte[] bitmapBytes)
 {
     using (var bitmapRepresentation = new BitmapRepresentation(bitmapBytes))
         using (var bmpEx = bitmapRepresentation.CreateBitmap())
             using (var result = LayoutContext.CreateBitmap())
             {
                 BitmapHelpers.ResizeBitmap(bmpEx, result);
                 return(new BitmapRepresentation(result));
             }
 }
示例#8
0
 public PlayingInfo(string title, string artist, string album, BitmapRepresentation bitmapRepresentation, bool isPlaying, TimeSpan durationSpan, TimeSpan currentPosition)
 {
     Title  = title;
     Artist = artist;
     Album  = album;
     BitmapRepresentation = bitmapRepresentation;
     IsPlaying            = isPlaying;
     DurationSpan         = durationSpan;
     CurrentPosition      = currentPosition;
 }
示例#9
0
        private void Draw()
        {
            if (_bitmapBytes != null && LayoutContext != null)
            {
                if (_bitmapRepresentation == null)
                {
                    _bitmapRepresentation = GetBitmapRepresentation(_bitmapBytes);
                }

                DrawInvoke(new[] { new LayoutDrawElement(new Location(0, 0), _bitmapRepresentation.Clone()) });
            }
        }
示例#10
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = (Title != null ? Title.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Artist != null ? Artist.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Album != null ? Album.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (BitmapRepresentation != null ? BitmapRepresentation.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ IsPlaying.GetHashCode();
         hashCode = (hashCode * 397) ^ DurationSpan.GetHashCode();
         hashCode = (hashCode * 397) ^ CurrentPosition.GetHashCode();
         return(hashCode);
     }
 }
示例#11
0
        public void TestExtractLayoutDrawElements()
        {
            Color green = Color.FromArgb(0, 200, 0);
            Color red   = Color.FromArgb(200, 0, 0);
            Color blue  = Color.FromArgb(0, 0, 200);

            Color black = Color.FromArgb(0, 0, 0);
            Color gray  = Color.FromArgb(100, 100, 100);
            Color white = Color.FromArgb(200, 200, 200);

            using (var bitmap = new Bitmap(30, 20))
            {
                using (var graphics = Graphics.FromImage(bitmap))
                    using (var rBrush = new SolidBrush(red))
                        using (var gBrush = new SolidBrush(green))
                            using (var bBrush = new SolidBrush(blue))
                                using (var bkBrush = new SolidBrush(black))
                                    using (var grBrush = new SolidBrush(gray))
                                        using (var wtBrush = new SolidBrush(white))
                                        {
                                            graphics.FillRectangle(rBrush, 0, 0, 10, 10);
                                            graphics.FillRectangle(gBrush, 10, 0, 10, 10);
                                            graphics.FillRectangle(bBrush, 20, 0, 10, 10);
                                            graphics.FillRectangle(bkBrush, 0, 10, 10, 10);
                                            graphics.FillRectangle(grBrush, 10, 10, 10, 10);
                                            graphics.FillRectangle(wtBrush, 20, 10, 10, 10);
                                        }

                var initializer = new Initializer();

                using (var sourceRepresentation = new BitmapRepresentation(bitmap))
                    using (var sourceBitmapEx = sourceRepresentation.CreateBitmap())
                    {
                        var ldes = BitmapHelpers.ExtractLayoutDrawElements(sourceBitmapEx, new DeviceSize(3, 2), 5, 3, initializer.LayoutContext).ToArray();

                        Assert.AreEqual(true, CheckColorOfElement(ldes, 5, 3, red));
                        Assert.AreEqual(true, CheckColorOfElement(ldes, 6, 3, green));
                        Assert.AreEqual(true, CheckColorOfElement(ldes, 7, 3, blue));
                        Assert.AreEqual(true, CheckColorOfElement(ldes, 5, 4, black));
                        Assert.AreEqual(true, CheckColorOfElement(ldes, 6, 4, gray));
                        Assert.AreEqual(true, CheckColorOfElement(ldes, 7, 4, white));
                    }
            }
        }
示例#12
0
        private void OnDrawLayout(object sender, DrawEventArgs e)
        {
            BitmapEx currentBitmap;

            lock (_bitmapLock)
            {
                currentBitmap = _currentRepresentation.CreateBitmap();
                foreach (var element in e.Elements)
                {
                    var destRect = new Rectangle(_buttonShift.Width + element.Location.X * _individualButtonSize.Width, _buttonShift.Height + element.Location.Y * _individualButtonSize.Height, _individualButtonSize.Width, _individualButtonSize.Height);
                    using (var sourceBitmap = element.BitmapRepresentation.CreateBitmap())
                    {
                        BitmapHelpers.ResizeBitmap(sourceBitmap, currentBitmap, destRect);
                        element.BitmapRepresentation.Dispose();
                    }
                }

                DisposeHelper.DisposeAndNull(ref _currentRepresentation);
                _currentRepresentation = new BitmapRepresentation(currentBitmap);
            }

            DrawInvoke(new[] { new LayoutDrawElement(new Location(0, 0), currentBitmap) });
        }
示例#13
0
        public void TestBitmapAllocations()
        {
            Bitmap bmp1;

            using (Bitmap srcBmp = new Bitmap(100, 100))
                using (BitmapRepresentation br = new BitmapRepresentation(srcBmp))
                    using (var bmpEx = br.CreateBitmap())
                    {
                        bmp1 = bmpEx.GetInternal();
                    }

            Bitmap bmp2;

            using (Bitmap srcBmp = new Bitmap(101, 100))
                using (BitmapRepresentation br = new BitmapRepresentation(srcBmp))
                    using (var bmpEx = br.CreateBitmap())
                    {
                        bmp2 = bmpEx.GetInternal();
                    }

            Bitmap bmp3;
            Bitmap bmp4;

            using (Bitmap srcBmp = new Bitmap(100, 100))
                using (BitmapRepresentation br = new BitmapRepresentation(srcBmp))
                {
                    using (var bmpEx1 = br.CreateBitmap())
                        using (var bmpEx2 = br.CreateBitmap())
                        {
                            bmp3 = bmpEx1.GetInternal();
                            bmp4 = bmpEx2.GetInternal();
                        }
                }
            Assert.AreEqual(bmp1, bmp3, "Instances of bitmaps of the same size are different");
            Assert.AreNotEqual(bmp1, bmp2, "Instances of bitmaps of different size are the same");
            Assert.AreNotEqual(bmp3, bmp4, "Not disposed image is used twice");
        }
示例#14
0
        private void PerformDraw(PlayingInfo playingInfo)
        {
            if (_previousRepresentation != playingInfo?.BitmapRepresentation || _prevPlaying != playingInfo?.IsPlaying)
            {
                _previousRepresentation = playingInfo?.BitmapRepresentation;
                _prevPlaying            = playingInfo?.IsPlaying ?? false;

                var bitmap = LayoutContext.CreateBitmap();

                if (playingInfo?.BitmapRepresentation != null)
                {
                    using (var coverBitmap = playingInfo.BitmapRepresentation.CreateBitmap())
                    {
                        BitmapHelpers.ResizeBitmap(coverBitmap, bitmap, _prevPlaying ? null : BitmapHelpers.GrayColorMatrix);
                    }
                }
                else
                {
                    DefaultDrawingAlgs.DrawText(bitmap, FontService.Instance.AwesomeFontFamily, FontAwesomeRes.fa_headphones, LayoutContext.Options.Theme.ForegroundColor);
                }

                DrawInvoke(new[] { new LayoutDrawElement(new Location(0, 0), bitmap, new TransitionInfo(TransitionType.ElementUpdate, TimeSpan.FromSeconds(1))) });
            }
        }
示例#15
0
        private static KeyBitmap FromBitmapRepresentation(BitmapRepresentation representation)
        {
            int width  = representation.Width;
            int height = representation.Height;

            byte[] bitmapData = new byte[width * height * 3];
            byte[] scan0      = representation.Bytes;

            var stride = scan0.Length / height;

            for (int y = 0; y < height; ++y)
            {
                for (int x = 0; x < width; ++x)
                {
                    int index3 = stride * y + x * 3;
                    int index4 = (width * y + x) * 3;
                    bitmapData[index4]     = scan0[index3];
                    bitmapData[index4 + 1] = scan0[index3 + 1];
                    bitmapData[index4 + 2] = scan0[index3 + 2];
                }
            }

            return(new KeyBitmap(width, height, bitmapData));
        }
示例#16
0
 public void ReplaceLastBitmap(BitmapRepresentation lastBitmapRepresentation)
 {
     _transition.ReplaceLastBitmap(lastBitmapRepresentation);
     DisposeHelper.DisposeAndNull(ref _last);
     _last = lastBitmapRepresentation;
 }
示例#17
0
 public void Init(BitmapRepresentation first, BitmapRepresentation last, int steps)
 {
     _current = last.Clone();
 }
示例#18
0
 public void ReplaceLastBitmap(BitmapRepresentation last)
 {
     DisposeHelper.DisposeAndNull(ref _current);
     _current = last.Clone();
 }
示例#19
0
文件: MediaLayout.cs 项目: tihilv/Vkm
        private void PerformDraw(PlayingInfo playingInfo)
        {
            byte imageSize = 2;
            byte textSize  = 3;
            var  result    = new List <LayoutDrawElement>();

            if (playingInfo.IsPlaying != _isPlaying)
            {
                _isPlaying = playingInfo.IsPlaying;
                _playPauseButton.ReplaceText(_isPlaying.Value?FontAwesomeRes.fa_pause:FontAwesomeRes.fa_play);
            }

            if (_previousRepresentation != playingInfo?.BitmapRepresentation)
            {
                _previousRepresentation = playingInfo?.BitmapRepresentation;

                using (var bitmap = new BitmapEx(LayoutContext.IconSize.Width * imageSize, LayoutContext.IconSize.Height * imageSize))
                {
                    bitmap.MakeTransparent();
                    if (playingInfo?.BitmapRepresentation != null)
                    {
                        using (BitmapEx coverBitmap = playingInfo.BitmapRepresentation.CreateBitmap())
                        {
                            BitmapHelpers.ResizeBitmap(coverBitmap, bitmap);
                        }
                    }

                    result.AddRange(BitmapHelpers.ExtractLayoutDrawElements(bitmap, new DeviceSize(imageSize, imageSize), 0, 0, LayoutContext));
                }
            }

            using (var bitmap = new BitmapEx(LayoutContext.IconSize.Width * textSize, LayoutContext.IconSize.Height))
            {
                var lineWidth = 0.05;

                bitmap.MakeTransparent();
                var title = playingInfo?.Title;
                DefaultDrawingAlgs.DrawText(bitmap, GlobalContext.Options.Theme.FontFamily, title, LayoutContext.Options.Theme.ForegroundColor);

                if (playingInfo != null)
                {
                    using (var graphics = bitmap.CreateGraphics())
                        using (var brush = new SolidBrush(GlobalContext.Options.Theme.ForegroundColor))
                        {
                            var rect = new Rectangle(0, (int)(bitmap.Height * (1 - lineWidth)), (int)(bitmap.Width * playingInfo.CurrentPosition.TotalMilliseconds / playingInfo.DurationSpan.TotalMilliseconds), (int)(bitmap.Height * lineWidth));
                            graphics.FillRectangle(brush, rect);
                        }
                }

                result.AddRange(BitmapHelpers.ExtractLayoutDrawElements(bitmap, new DeviceSize(textSize, 1), imageSize, 0, LayoutContext));
            }

            using (var bitmap = new BitmapEx(LayoutContext.IconSize.Width * textSize, LayoutContext.IconSize.Height))
            {
                bitmap.MakeTransparent();
                var artist = playingInfo?.Artist ?? string.Empty;
                var album  = playingInfo?.Album ?? string.Empty;
                var text   = $"{artist}\n{album}";
                DefaultDrawingAlgs.DrawText(bitmap, GlobalContext.Options.Theme.FontFamily, text, GlobalContext.Options.Theme.ForegroundColor);
                result.AddRange(BitmapHelpers.ExtractLayoutDrawElements(bitmap, new DeviceSize(textSize, 1), imageSize, 1, LayoutContext));
            }

            DrawInvoke(result);
        }
示例#20
0
 public LayoutDrawElement(Location location, BitmapRepresentation bitmapRepresentation, TransitionInfo transitionInfo = default(TransitionInfo))
 {
     Location             = location;
     BitmapRepresentation = bitmapRepresentation;
     TransitionInfo       = transitionInfo;
 }
示例#21
0
 public void Dispose()
 {
     BitmapRepresentation?.Dispose();
 }