コード例 #1
0
        async Task <Bitmap> PortableAsyncRenderer <Bitmap> .GetThumbnailAsync
        (
            PortableCorrelatedEntity correlatedEntity,
            Func <string> correlationTag,
            int viewWidth,
            int viewHeight//,
            //Bitmap reusedThumbnail
        )
        {
            if (correlatedEntity.CorrelationTag != correlationTag())
            {
                return(null);
            }

            Task <Bitmap> thumbnailTask = ThumbnailUtils.CreateVideoThumbnailAsync
                                          (
                FilePath,
                ThumbnailKind.MicroKind
                                          );

            if (thumbnailTask.Result == null)
            {
                throw new CorruptObjectException(FileName);
            }

            return(await thumbnailTask);
        }
コード例 #2
0
        internal static async Task <StorageItemThumbnail> CreateVideoThumbnailAsync(StorageFile file)
        {
            var bmp = await ThumbnailUtils.CreateVideoThumbnailAsync(file.Path, Android.Provider.ThumbnailKind.MiniKind);

            MemoryStream stream = new MemoryStream();
            await bmp.CompressAsync(Bitmap.CompressFormat.Jpeg, 90, stream);

            stream.Seek(0, SeekOrigin.Begin);
            return(new StorageItemThumbnail(stream));
        }
コード例 #3
0
ファイル: ViewHolders.cs プロジェクト: vikingcodes/OurPlace
        private async Task LoadThumbIntoImageList(string imagePath, Activity context)
        {
            Bitmap thumb = await ThumbnailUtils.CreateVideoThumbnailAsync(imagePath, ThumbnailKind.MiniKind);
            ImageViewAsync newImage = new ImageViewAsync(context);
            newImage.SetPadding(10, 10, 10, 10);

            ItemList.AddView(newImage);
            newImage.SetImageBitmap(thumb);

            newImage.Click += Item_Click;
        }
コード例 #4
0
        private async void FixMissing()
        {
            List <string> missing = new List <string>();

            //look in fixing dir
            DirSearch(GetExternalPath() + "/missing", missing);

            await Bootlegger.BootleggerClient.OfflineConnect(CurrentEvent.id, cancel.Token);

            //for each, create new clip
            foreach (var file in missing)
            {
                FileInfo ff       = new FileInfo(file);
                var      filename = ff.Name;
                var      group    = ff.Directory.Name;

                //generate thumbnail
                Bootlegger.BootleggerClient.CurrentClientRole = Bootlegger.BootleggerClient.CurrentEvent.roles.First();
                //var ev = await Bootlegger.BootleggerClient.GetEventInfo(CurrentEvent.id,new CancellationTokenSource().Token);
                Bootlegger.BootleggerClient.SetShot(Bootlegger.BootleggerClient.CurrentClientRole.Shots.First());

                Dictionary <string, string> meta = new Dictionary <string, string>();

                try
                {
                    FileStream outt;
                    var        bitmap = await ThumbnailUtils.CreateVideoThumbnailAsync(file, Android.Provider.ThumbnailKind.MiniKind);

                    outt = new FileStream(file + ".jpg", FileMode.CreateNew);
                    await bitmap.CompressAsync(Android.Graphics.Bitmap.CompressFormat.Jpeg, 90, outt);

                    outt.Close();
                }
                catch
                {
                }


                meta.Add("captured_at", ff.CreationTime.ToString("dd/MM/yyyy H:mm:ss.ff tt zz"));
                MediaItem newm = new MediaItem();
                newm.Filename = file;
                //add to upload queue (for the right user)
                var mediaitem = Bootlegger.BootleggerClient.CreateMediaMeta(newm, meta, null, file + ".jpg");
                Bootlegger.BootleggerClient.UnSelectRole(!WhiteLabelConfig.REDUCE_BANDWIDTH, true);
            }
        }
コード例 #5
0
        async Task <FileData> GetFileData(Android.Net.Uri p_uri)
        {
            var filePath = IOUtil.GetPath(_context, p_uri);

            if (string.IsNullOrEmpty(filePath))
            {
                filePath = IOUtil.IsMediaStore(p_uri.Scheme) ? p_uri.ToString() : p_uri.Path;
            }
            var fileName = GetFileName(_context, p_uri);

            var    fd  = new FileData(filePath, fileName, (ulong)new File(filePath).Length());
            string ext = fd.Ext;

            // 生成文件描述和缩略图
            if (FileFilter.UwpImage.Contains(ext))
            {
                BitmapFactory.Options options = new BitmapFactory.Options();
                // 只解析图片大小,不加载内容
                options.InJustDecodeBounds = true;
                BitmapFactory.DecodeFile(filePath, options);
                fd.Desc = $"{options.OutWidth} x {options.OutHeight} ({ext.TrimStart('.')})";

                int maxSize = Math.Max(options.OutWidth, options.OutHeight);
                if (maxSize > FileData.ThumbSize)
                {
                    // 直接按缩放比例加载
                    options.InJustDecodeBounds = false;
                    options.InSampleSize       = maxSize / FileData.ThumbSize;
                    // v29 弃用
                    //options.InPurgeable = true;
                    Bitmap bmp = BitmapFactory.DecodeFile(filePath, options);

                    fd.ThumbPath = System.IO.Path.Combine(Kit.CachePath, Kit.NewGuid + "-t.jpg");
                    using (var fs = System.IO.File.Create(fd.ThumbPath))
                    {
                        await bmp.CompressAsync(Android.Graphics.Bitmap.CompressFormat.Jpeg, 100, fs);
                    }
                    bmp.Recycle();
                }
            }
            else if (FileFilter.UwpVideo.Contains(ext))
            {
                Android.Media.MediaMetadataRetriever media = new Android.Media.MediaMetadataRetriever();
                try
                {
                    await media.SetDataSourceAsync(filePath);

                    string dur    = media.ExtractMetadata(Android.Media.MetadataKey.Duration);
                    string width  = media.ExtractMetadata(Android.Media.MetadataKey.VideoWidth);
                    string height = media.ExtractMetadata(Android.Media.MetadataKey.VideoHeight);
                    fd.Desc = string.Format("{0:HH:mm:ss} ({1} x {2})", new DateTime(long.Parse(dur) * 10000), width, height);
                }
                catch { }
                finally
                {
                    media.Release();
                }

                // 帧缩略图
                var bmp = await ThumbnailUtils.CreateVideoThumbnailAsync(filePath, ThumbnailKind.MiniKind);

                fd.ThumbPath = System.IO.Path.Combine(Kit.CachePath, Kit.NewGuid + "-t.jpg");
                using (var fs = System.IO.File.Create(fd.ThumbPath))
                {
                    await bmp.CompressAsync(Android.Graphics.Bitmap.CompressFormat.Jpeg, 100, fs);
                }
                bmp.Recycle();
            }
            else if (FileFilter.UwpAudio.Contains(ext))
            {
                Android.Media.MediaMetadataRetriever media = new Android.Media.MediaMetadataRetriever();
                try
                {
                    await media.SetDataSourceAsync(filePath);

                    string dur = media.ExtractMetadata(Android.Media.MetadataKey.Duration);
                    fd.Desc = string.Format("{0:mm:ss}", new DateTime(long.Parse(dur) * 10000));
                }
                catch { }
                finally
                {
                    media.Release();
                }
            }
            return(fd);
        }
コード例 #6
0
        public static async Task <Bitmap> createVideoBitmapAsync(int width, int height, string videoFilePath)
        {
            Bitmap videoThumbnail = await ThumbnailUtils.CreateVideoThumbnailAsync(videoFilePath, ThumbnailKind.MicroKind);

            return(Bitmap.CreateScaledBitmap(videoThumbnail, width, height, false));
        }
コード例 #7
0
        protected override async void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);

            if (resultCode != Result.Ok)
            {
                if (!string.IsNullOrEmpty(_path) && File.Exists(_path))
                {
                    try
                    {
                        File.Delete(_path);
                    }
                    catch { }
                }
                OnCaptured(null);
                Finish();
                return;
            }

            try
            {
                FileData fd  = new FileData(_path, System.IO.Path.GetFileName(_path), (ulong)new Java.IO.File(_path).Length());
                string   ext = fd.Ext;

                // 生成文件描述和缩略图
                if (ext == ".jpg")
                {
                    BitmapFactory.Options options = new BitmapFactory.Options();
                    // 只解析图片大小,不加载内容
                    options.InJustDecodeBounds = true;
                    BitmapFactory.DecodeFile(_path, options);
                    fd.Desc = $"{options.OutWidth} x {options.OutHeight} ({ext.TrimStart('.')})";

                    int maxSize = Math.Max(options.OutWidth, options.OutHeight);
                    if (maxSize > FileData.ThumbSize)
                    {
                        // 直接按缩放比例加载
                        options.InJustDecodeBounds = false;
                        options.InSampleSize       = maxSize / FileData.ThumbSize;
                        // v29 弃用
                        //options.InPurgeable = true;
                        Bitmap bmp = BitmapFactory.DecodeFile(_path, options);

                        fd.ThumbPath = System.IO.Path.Combine(Kit.CachePath, Kit.NewGuid + "-t.jpg");
                        using (var fs = System.IO.File.Create(fd.ThumbPath))
                        {
                            await bmp.CompressAsync(Android.Graphics.Bitmap.CompressFormat.Jpeg, 100, fs);
                        }
                        bmp.Recycle();
                    }
                }
                else if (ext == ".mp4")
                {
                    Android.Media.MediaMetadataRetriever media = new Android.Media.MediaMetadataRetriever();
                    try
                    {
                        await media.SetDataSourceAsync(_path);

                        string dur    = media.ExtractMetadata(Android.Media.MetadataKey.Duration);
                        string width  = media.ExtractMetadata(Android.Media.MetadataKey.VideoWidth);
                        string height = media.ExtractMetadata(Android.Media.MetadataKey.VideoHeight);
                        fd.Desc = string.Format("{0:HH:mm:ss} ({1} x {2})", new DateTime(long.Parse(dur) * 10000), width, height);
                    }
                    catch { }
                    finally
                    {
                        media.Release();
                    }

                    // 帧缩略图
                    var bmp = await ThumbnailUtils.CreateVideoThumbnailAsync(_path, ThumbnailKind.MiniKind);

                    fd.ThumbPath = System.IO.Path.Combine(Kit.CachePath, Kit.NewGuid + "-t.jpg");
                    using (var fs = System.IO.File.Create(fd.ThumbPath))
                    {
                        await bmp.CompressAsync(Android.Graphics.Bitmap.CompressFormat.Jpeg, 100, fs);
                    }
                    bmp.Recycle();
                }
                OnCaptured(fd);
            }
            catch
            {
                OnCaptured(null);
            }
            finally
            {
                Finish();
            }
        }