private bool TrySetWebPSource(TLDocument document, int phase) { if (phase >= Phase && document != null) { var fileName = document.GetFileName(); if (File.Exists(FileUtils.GetTempFileName(fileName))) { Phase = phase; //Image.UriSource = FileUtils.GetTempFileUri(fileName); var decoded = WebPImage.Encode(File.ReadAllBytes(FileUtils.GetTempFileName(fileName))); if (decoded != null) { _bitmapImage.SetSource(decoded); } else { _bitmapImage.UriSource = FileUtils.GetTempFileUri(fileName); } return(true); } } return(false); }
private void SetWebPSource(ITLTransferable transferable, TLFileLocation location, int fileSize, int phase) { if (phase >= Phase && location != null) { Phase = phase; var fileName = string.Format("{0}_{1}_{2}.jpg", location.VolumeId, location.LocalId, location.Secret); if (File.Exists(FileUtils.GetTempFileName(fileName))) { //Image.UriSource = FileUtils.GetTempFileUri(fileName); _bitmapImage.SetSource(WebPImage.Encode(File.ReadAllBytes(FileUtils.GetTempFileName(fileName)))); } else { Execute.BeginOnThreadPool(async() => { var result = await _downloadManager.DownloadFileAsync(location, fileSize).AsTask(transferable?.Download()); if (result != null && Phase <= phase) { Execute.BeginOnUIThread(() => { if (transferable != null) { transferable.IsTransferring = false; } //Image.UriSource = FileUtils.GetTempFileUri(fileName); _bitmapImage.SetSource(WebPImage.Encode(File.ReadAllBytes(FileUtils.GetTempFileName(fileName)))); }); } }); } } }
private void SetWebPSource(ITLTransferable transferable, TLDocument document, int fileSize, int phase) { if (phase >= Phase && document != null) { Phase = phase; var fileName = document.GetFileName(); if (File.Exists(FileUtils.GetTempFileName(fileName))) { //Image.UriSource = FileUtils.GetTempFileUri(fileName); Image.SetSource(WebPImage.Encode(File.ReadAllBytes(FileUtils.GetTempFileName(fileName)))); } else { Execute.BeginOnThreadPool(async() => { var result = await _downloadFileManager.DownloadFileAsync(fileName, document.DCId, document.ToInputFileLocation(), fileSize).AsTask(transferable?.Download()); if (result != null && Phase <= phase) { Execute.BeginOnUIThread(() => { if (transferable != null) { transferable.IsTransferring = false; } //Image.UriSource = FileUtils.GetTempFileUri(fileName); Image.SetSource(WebPImage.Encode(File.ReadAllBytes(FileUtils.GetTempFileName(fileName)))); }); } }); } } }
public void Highlight() { var message = DataContext as TLMessage; if (message == null) { return; } var sticker = message.IsSticker(); var round = message.IsRoundVideo(); var target = sticker || round ? Media : (FrameworkElement)ContentPanel; var overlay = ElementCompositionPreview.GetElementChildVisual(target) as SpriteVisual; if (overlay == null) { overlay = ElementCompositionPreview.GetElementVisual(this).Compositor.CreateSpriteVisual(); ElementCompositionPreview.SetElementChildVisual(target, overlay); } var settings = new UISettings(); var fill = overlay.Compositor.CreateColorBrush(settings.GetColorValue(UIColorType.Accent)); var brush = (CompositionBrush)fill; if (sticker || round) { ImageLoader.Initialize(overlay.Compositor); ManagedSurface surface = null; if (sticker) { var document = message.GetDocument(); var fileName = document.GetFileName(); if (File.Exists(FileUtils.GetTempFileName(fileName))) { var decoded = WebPImage.Encode(File.ReadAllBytes(FileUtils.GetTempFileName(fileName))); surface = ImageLoader.Instance.LoadFromStream(decoded); } } else { surface = ImageLoader.Instance.LoadCircle(100, Windows.UI.Colors.White); } if (surface != null) { var mask = overlay.Compositor.CreateMaskBrush(); mask.Mask = surface.Brush; mask.Source = fill; brush = mask; } } overlay.Size = new System.Numerics.Vector2((float)target.ActualWidth, (float)target.ActualHeight); overlay.Opacity = 0f; overlay.Brush = brush; var animation = overlay.Compositor.CreateScalarKeyFrameAnimation(); animation.Duration = TimeSpan.FromSeconds(2); animation.InsertKeyFrame(300f / 2000f, 0.4f); animation.InsertKeyFrame(1700f / 2000f, 0.4f); animation.InsertKeyFrame(1, 0); overlay.StartAnimation("Opacity", animation); }