Exemplo n.º 1
0
        private bool PopulateThumbnailAndMetaData(MediaItem mediaItem)
        {
            byte[] thumb = null;

            if (mediaItem.ThumbnailImageSource == null)
            {
                // ReSharper disable once StyleCop.SA1117
                thumb = _thumbnailService.GetThumbnail(
                    mediaItem.FilePath,
                    Unosquare.FFME.MediaElement.FFmpegDirectory,
                    mediaItem.MediaType.Classification,
                    mediaItem.LastChanged,
                    out var _);

                if (thumb == null)
                {
                    return(false);
                }
            }

            DispatcherHelper.CheckBeginInvokeOnUI(() =>
            {
                mediaItem.ThumbnailImageSource = GraphicsUtils.ByteArrayToImage(thumb);
            });

            return(true);
        }
Exemplo n.º 2
0
        private void PopulateThumbnail(MediaItem mediaItem)
        {
            if (!IsThumbnailPopulated(mediaItem))
            {
                // ReSharper disable once StyleCop.SA1117
                byte[] thumb = _thumbnailService.GetThumbnail(
                    mediaItem.FilePath,
                    Unosquare.FFME.MediaElement.FFmpegDirectory,
                    mediaItem.MediaType.Classification,
                    mediaItem.LastChanged,
                    out var _);

                if (thumb != null)
                {
                    DispatcherHelper.CheckBeginInvokeOnUI(() =>
                    {
                        mediaItem.ThumbnailImageSource = GraphicsUtils.ByteArrayToImage(thumb);
                    });
                }
            }
        }
Exemplo n.º 3
0
        private async Task PopulateThumbnailAsync(MediaItem mediaItem)
        {
            if (mediaItem.FilePath != null && mediaItem.MediaType != null && !IsThumbnailPopulated(mediaItem))
            {
                byte[]? thumb = null;

                await Task.Run(
                    () =>
                {
                    thumb = _thumbnailService.GetThumbnail(
                        mediaItem.FilePath,
                        Unosquare.FFME.Library.FFmpegDirectory,
                        mediaItem.MediaType.Classification,
                        mediaItem.LastChanged,
                        out var _);
                }, _cancellationToken);

                if (thumb != null && !IsThumbnailPopulated(mediaItem) && !_cancellationToken.IsCancellationRequested)
                {
                    mediaItem.ThumbnailImageSource = GraphicsUtils.ByteArrayToImage(thumb);
                }
            }
        }
Exemplo n.º 4
0
        private byte[] CreateFramedSmallIcon(byte[] bytes)
        {
            const int pixelSize = 100;

            var image = GraphicsUtils.ByteArrayToImage(bytes);

            if (Math.Max(image.Height, image.Width) < pixelSize)
            {
                var visual = new DrawingVisual();
                using (var drawingContext = visual.RenderOpen())
                {
                    drawingContext.DrawRectangle(
                        System.Windows.Media.Brushes.Black,
                        null,
                        new Rect(0, 0, pixelSize, pixelSize));

                    var left = (pixelSize - image.Width) / 2;
                    var top  = (pixelSize - image.Height) / 2;

                    drawingContext.DrawImage(image, new Rect(left, top, image.Width, image.Height));
                }

                var bitmap = new RenderTargetBitmap(pixelSize, pixelSize, 96, 96, PixelFormats.Pbgra32);
                bitmap.Render(visual);

                var encoder = new PngBitmapEncoder();
                encoder.Frames.Add(BitmapFrame.Create(bitmap));

                using (var stream = new MemoryStream())
                {
                    encoder.Save(stream);
                    bytes = stream.ToArray();
                }
            }

            return(bytes);
        }