public MediaDetailPage(MediaDetails media) { Title = ApplicationResource.PageMediaDetailTitle; BindingContext = new MediaDetailViewModel(this.Navigation, media); var image = new CachedImage { Aspect = Aspect.AspectFill }; image.SetBinding(CachedImage.SourceProperty, "MediaFilePath"); var deleteToolbarItem = new ToolbarItem() { Text = "Delete" }; deleteToolbarItem.Command = new Command(async() => await PromptDeleteMedia()); //deleteToolbarItem.SetBinding(ToolbarItem.CommandProperty, new Binding("DeleteMediaCommand")); ToolbarItems.Add(deleteToolbarItem); var layout = new StackLayout { HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.CenterAndExpand, Children = { image } }; Content = layout; }
async Task PickPhoto() { var hasPermission = await PermissionsCheck.PhotosAsync(); if (!hasPermission) { return; } var file = await CrossMedia.Current.PickPhotoAsync(new PickMediaOptions { PhotoSize = PhotoSize.Full }); if (file == null) { return; } predictionMedia = new Models.MediaDetails() { Path = file.Path, PreviewPath = file.Path, Type = MediaFileType.Image, Date = DateTime.Now }; database.SaveItem(predictionMedia); SetPageState(PredictionPageState.Uploading); await UploadMedia(predictionMedia.FullPath); }
public bool DeleteItem(MediaDetails item) { FileHelper.DeleteLocalFiles(item); var result = mediaCollection.Delete(item.Id); return(result); }
MediaDetails CreateMediaFileFromUri(Android.Net.Uri uri) { MediaDetails mediaFile = null; var type = CrossCurrentActivity.Current.Activity.ContentResolver.GetType(uri); var path = GetRealPathFromURI(uri); if (path != null) { string fullPath = string.Empty; string thumbnailImagePath = string.Empty; var fileName = System.IO.Path.GetFileNameWithoutExtension(path); var ext = System.IO.Path.GetExtension(path) ?? string.Empty; MediaFileType mediaFileType = MediaFileType.Image; if (type.StartsWith(Enum.GetName(typeof(MediaFileType), MediaFileType.Image), StringComparison.CurrentCultureIgnoreCase)) { var fullImage = ImageHelpers.RotateImage(path, 1); var thumbImage = ImageHelpers.RotateImage(path, 0.25f); fullPath = FileHelper.GetOutputPath(MediaFileType.Image, $"{fileName}{ext}"); File.WriteAllBytes(fullPath, fullImage); thumbnailImagePath = FileHelper.GetOutputPath(MediaFileType.Image, $"{fileName}-THUMBNAIL{ext}"); File.WriteAllBytes(thumbnailImagePath, thumbImage); } else if (type.StartsWith(Enum.GetName(typeof(MediaFileType), MediaFileType.Video), StringComparison.CurrentCultureIgnoreCase)) { fullPath = path; var bitmap = ThumbnailUtils.CreateVideoThumbnail(path, ThumbnailKind.MiniKind); thumbnailImagePath = FileHelper.GetOutputPath(MediaFileType.Image, $"{fileName}-THUMBNAIL{ext}"); var stream = new FileStream(thumbnailImagePath, FileMode.Create); bitmap?.Compress(Bitmap.CompressFormat.Jpeg, ProjectConfig.JpegCompression, stream); stream.Close(); mediaFileType = MediaFileType.Video; } if (!string.IsNullOrEmpty(fullPath) && !string.IsNullOrEmpty(thumbnailImagePath)) { mediaFile = new MediaDetails() { Path = fullPath, Type = mediaFileType, PreviewPath = thumbnailImagePath, Date = DateTime.Now }; } } return(mediaFile); }
public MediaDetailViewModel(INavigation navigation, MediaDetails media) { Navigation = navigation; database = ServiceContainer.Resolve <IDatabase>(); this.media = media; DeleteMediaCommand = new Command(async(obj) => { database.DeleteItem(media); await navigation.PopAsync(); }); }
public static void DeleteLocalFiles(MediaDetails media) { var fullPath = media.FullPath; if (File.Exists(fullPath)) { File.Delete(fullPath); } var fullPreviewPath = media.FullPreviewPath; if (File.Exists(fullPreviewPath)) { File.Delete(fullPreviewPath); } }
public string SaveBytes(byte[] bytes) { var fileName = Guid.NewGuid() + ".jpg"; var media = new MediaDetails() { Path = fileName, PreviewPath = fileName, Type = MediaFileType.Image, Date = DateTime.Now }; File.WriteAllBytes(media.FullPath, bytes); database.SaveItem(media); return(fileName); }
public async Task SaveBytes(byte[] bytes) { SetPageState(PredictionPageState.Uploading); var fileName = Guid.NewGuid() + ".jpg"; predictionMedia = new Models.MediaDetails() { Path = fileName, PreviewPath = fileName, Type = MediaFileType.Image, Date = DateTime.Now }; File.WriteAllBytes(predictionMedia.FullPath, bytes); database.SaveItem(predictionMedia); await UploadMedia(predictionMedia.FullPath); }
public PredictionResultsPage(MediaDetails media, ImagePrediction prediction) { Title = ApplicationResource.PagePredictionResultsTitle; BindingContext = viewModel = new PredictionResultsViewModel(Navigation, media, prediction); viewModel.PredictionsChanged += OnPredictionsChanged; var screenSize = new Size(App.ScreenWidth, App.ScreenHeight); // Image View photoView = new Image(); photoView.Source = ImageSource.FromFile(media.FullPath); AbsoluteLayout.SetLayoutBounds(photoView, new Rectangle(0, 0, 1, 1)); AbsoluteLayout.SetLayoutFlags(photoView, AbsoluteLayoutFlags.All); // Canvas View canvasView = new SKCanvasView(); canvasView.PaintSurface += OnCanvasViewPaintSurface; AbsoluteLayout.SetLayoutBounds(canvasView, new Rectangle(0, 0, 1, 1)); AbsoluteLayout.SetLayoutFlags(canvasView, AbsoluteLayoutFlags.All); // Slider view Slider confidenceSlider = new Slider() { Minimum = 0, Maximum = 1 }; confidenceSlider.SetBinding(Slider.ValueProperty, new Binding("Confidence")); AbsoluteLayout.SetLayoutBounds(confidenceSlider, new Rectangle(.5, 1, .8, .1)); AbsoluteLayout.SetLayoutFlags(confidenceSlider, AbsoluteLayoutFlags.All); var layout = new AbsoluteLayout(); layout.Margin = new Thickness(10); layout.Children.Add(photoView); layout.Children.Add(canvasView); layout.Children.Add(confidenceSlider); layout.SizeChanged += Layout_SizeChanged; Content = layout; var orientation = ImageUtils.GetImageOrientation(media.FullPath); imageBytes = File.ReadAllBytes(media.FullPath); masterBitmap = ImageUtils.HandleOrientation(SKBitmap.Decode(imageBytes), orientation); }
public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(System.Net.HttpStatusCode.BadRequest)); } Media med = _db.Media.Find(id); var revs = _db.Reviews.Where(e => e.MediaID == id); if (med == null) { return(new HttpStatusCodeResult(System.Net.HttpStatusCode.NotFound)); } MediaDetails medD = new MediaDetails { MediaID = med.MediaID, AgeRating = med.AgeRating, Description = med.Description, Name = med.Name, Reviews = revs.ToList <Review>() }; return(View(medD)); }
public static async Task <bool> UploadTrainingMedia(MediaDetails file) { var data = new MediaTrainingData() { Location = file.Location, MediaType = file.Type, Tags = file.Tags, SubmissionId = Settings.UserId }; byte[] image = File.ReadAllBytes(file.FullPath); var stringContent = new StringContent(JsonConvert.SerializeObject(data)); var content = new Dictionary <string, HttpContent>(); using (var memoryStream = new MemoryStream(image)) { using (var stream = new StreamContent(memoryStream)) { content.Add(HttpContentIds.Image, stream); content.Add(HttpContentIds.Data, stringContent); var response = await PostMultipartRequest <BaseResponse>(ProjectConfig.SubmitTrainingMediaUrl, content); var result = (response.StatusCode == (int)HttpStatusCode.OK); if (!result) { await App.Current.MainPage.DisplayAlert( ApplicationResource.GeneralErrorTitle, "(UploadTrainingMedia) " + response.Message, ApplicationResource.OK); } return(result); } } }
public ErrCode SaveMediaTran(MediaDetails media, out int id) { ErrCode err = new ErrCode(); id = 0; err = SiteProvider.CurrentProvider.SaveMediaTran(media, out id); return err; }
public int SaveItem(MediaDetails item) { return(mediaCollection.Insert(item)); }
async void FinishedPickingAssets(object sender, MultiAssetEventArgs args) { IList <MediaDetails> results = new List <MediaDetails>(); TaskCompletionSource <IList <MediaDetails> > tcs = new TaskCompletionSource <IList <MediaDetails> >(); var options = new PHImageRequestOptions() { NetworkAccessAllowed = true }; options.Synchronous = false; options.ResizeMode = PHImageRequestOptionsResizeMode.Fast; options.DeliveryMode = PHImageRequestOptionsDeliveryMode.HighQualityFormat; bool completed = false; for (var i = 0; i < args.Assets.Length; i++) { var asset = args.Assets[i]; string fileName = string.Empty; if (UIDevice.CurrentDevice.CheckSystemVersion(9, 0)) { fileName = PHAssetResource.GetAssetResources(asset).FirstOrDefault().OriginalFilename; } switch (asset.MediaType) { case PHAssetMediaType.Video: PHImageManager.DefaultManager.RequestImageForAsset(asset, new SizeF(150.0f, 150.0f), PHImageContentMode.AspectFill, options, async(img, info) => { var startIndex = fileName.IndexOf(".", StringComparison.CurrentCulture); string relativePath = ""; if (startIndex != -1) { relativePath = FileHelper.GetOutputPath(MediaFileType.Image, $"{fileName.Substring(0, startIndex)}-THUMBNAIL.JPG"); } else { relativePath = FileHelper.GetOutputPath(MediaFileType.Image, string.Empty); } if (!File.Exists(relativePath)) { var fullPath = FileHelper.GetFullPath(relativePath); img.AsJPEG().Save(fullPath, true); } TaskCompletionSource <string> tvcs = new TaskCompletionSource <string>(); var vOptions = new PHVideoRequestOptions(); vOptions.NetworkAccessAllowed = true; vOptions.Version = PHVideoRequestOptionsVersion.Original; vOptions.DeliveryMode = PHVideoRequestOptionsDeliveryMode.FastFormat; PHImageManager.DefaultManager.RequestAvAsset(asset, vOptions, (avAsset, audioMix, vInfo) => { var vPath = FileHelper.GetOutputPath(MediaFileType.Video, fileName); if (!File.Exists(vPath)) { AVAssetExportSession exportSession = new AVAssetExportSession(avAsset, AVAssetExportSession.PresetHighestQuality); exportSession.OutputUrl = NSUrl.FromFilename(vPath); exportSession.OutputFileType = AVFileType.QuickTimeMovie; exportSession.ExportAsynchronously(() => { Console.WriteLine(exportSession.Status); tvcs.TrySetResult(vPath); //exportSession.Dispose(); }); } }); var videoUrl = await tvcs.Task; var meFile = new MediaDetails() { Type = MediaFileType.Video, Path = videoUrl, PreviewPath = relativePath, Date = DateTime.Now }; results.Add(meFile); OnMediaPicked?.Invoke(this, meFile); if (args.Assets.Length == results.Count && !completed) { completed = true; tcs.TrySetResult(results); } }); break; default: PHImageManager.DefaultManager.RequestImageData(asset, options, (data, dataUti, orientation, info) => { if (fileName.EndsWith(".HEIC", StringComparison.CurrentCulture)) { fileName = Path.GetFileNameWithoutExtension(fileName) + ".jpg"; } var relativePath = FileHelper.GetOutputPath(MediaFileType.Image, fileName); var fullPath = FileHelper.GetFullPath(relativePath); if (!File.Exists(fullPath)) { Debug.WriteLine(dataUti); var image = UIImage.LoadFromData(data); var imageData = image.AsJPEG(ProjectConfig.JpegCompression / 100); imageData?.Save(fullPath, true); } var meFile = new MediaDetails() { Type = MediaFileType.Image, Path = relativePath, PreviewPath = relativePath, Date = DateTime.Now }; results.Add(meFile); OnMediaPicked?.Invoke(this, meFile); if (args.Assets.Length == results.Count && !completed) { completed = true; tcs.TrySetResult(results); } }); break; } } mediaPickTcs?.TrySetResult(await tcs.Task); }
public async Task <IEnumerable <MediaDetails> > FilterTimelineAsync(string username, DateTime earliest, DateTime latest) { Log("Examining account timeline: " + username); var tweets = await RetrieveTweets(username, earliest, latest); var filtered = tweets.Where(tweetFilter); var medias = filtered.SelectMany(t => t.Media.Where(mediaFilter).Select((m, i) => MediaDetails.From(t, m, i))); Log("Total tweets found: " + tweets.Count()); Log("Total tweets included: " + filtered.Count()); Log("Total media items: " + medias.Count()); return(medias); }
// protected string MediaDirectory(MediaDetails media) => media.Created.ToString("yyyy-MM-dd"); protected string MediaDirectory(MediaDetails media) => media.Created.ToString("yyyy-MM");