Example #1
0
        public static ImageSource GetBitmap(IProtoService protoService, File file, int width, int height)
        {
            if (file.Local.IsFileExisting())
            {
                return(UriEx.ToBitmap(file.Local.Path, width, height));
            }
            else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive && protoService != null)
            {
                protoService.DownloadFile(file.Id, 1);
            }

            return(null);
        }
Example #2
0
        public static async Task <ImageSource> GetWebPFrameAsync(string path, double maxWidth = 512)
        {
            try
            {
                Size size;
                var  buffer = await Task.Run(() => PlaceholderImageHelper.Current.DrawWebP(path, (int)maxWidth, out size));

                if (size.Width > 0 && size.Height > 0)
                {
                    var bitmap = new WriteableBitmap((int)size.Width, (int)size.Height);
                    buffer.CopyTo(bitmap.PixelBuffer);

                    return(bitmap);
                }
                else
                {
                    return(new BitmapImage(UriEx.ToLocal(path)));
                }
            }
            catch { }

            return(null);
        }