private async Task PickImage() { var filePicker = new FileOpenPicker { ViewMode = PickerViewMode.Thumbnail, SuggestedStartLocation = PickerLocationId.PicturesLibrary, FileTypeFilter = { ".png", ".jpg", ".jpeg" } }; var file = await filePicker.PickSingleFileAsync(); if (file != null && ImageCropper != null) { await ImageCropper.LoadImageFromFile(file); return; } var dispatcherQueue = Windows.System.DispatcherQueue.GetForCurrentThread(); await dispatcherQueue.EnqueueAsync(() => { Frame.GoBack(); }); }
private async void SelectFromGalleryButtonClick(object sender, RoutedEventArgs e) { FileOpenPicker openPicker = new FileOpenPicker(); openPicker.ViewMode = PickerViewMode.Thumbnail; openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; openPicker.FileTypeFilter.Add(".jpg"); openPicker.FileTypeFilter.Add(".bmp"); //openPicker.FileTypeFilter.Add(".gif"); openPicker.FileTypeFilter.Add(".png"); StorageFile imgFile = await openPicker.PickSingleFileAsync(); if (imgFile != null) { Helper.CreateCachedFolder(); Helper.CreateCachedFolder(); Helper.CreateCachedFolder(); Helper.CreateCachedFolder(); //var wb = new WriteableBitmap(1, 1); ShowEditor(); //await wb.LoadAsync(imgFile); //ImageCropper.SourceImage = wb; ImageCropper.AspectRatio = 1d; ImageCropper.CropShape = CropShape.Circular; await ImageCropper.LoadImageFromFile(imgFile); } }
public async void OnXamlRendered(FrameworkElement control) { _imageCropper = control.FindChild("ImageCropper") as ImageCropper; if (_imageCropper != null) { var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/Photos/Owl.jpg")); await _imageCropper.LoadImageFromFile(file); } }
private async void PickImgButton_Click(object sender, RoutedEventArgs e) { var openPicker = new FileOpenPicker { ViewMode = PickerViewMode.Thumbnail, SuggestedStartLocation = PickerLocationId.PicturesLibrary }; openPicker.FileTypeFilter.Add(".png"); openPicker.FileTypeFilter.Add(".jpg"); openPicker.FileTypeFilter.Add(".jpeg"); var file = await openPicker.PickSingleFileAsync(); if (file != null) await ImageCropper.LoadImageFromFile(file); }
async void ImportFile(StorageFile file) { try { var editNeeded = false; double width = 0, height = 0; var decoder = await BitmapDecoder.CreateAsync(await file.OpenReadAsync()); width = decoder.PixelWidth; height = decoder.PixelHeight; var wRatio = AspectRatioHelper.GetAspectRatioForMedia(width, height); var hRatio = AspectRatioHelper.GetAspectRatioForMedia(height, width); //if (wRatio > 1.91 && wRatio < 0.8) // editNeeded = true; //else //{ // if (hRatio > 1.91 && hRatio < 0.8) // editNeeded = true; //} //if (height > width) editNeeded = true; if (!editNeeded) { CropGrid.Visibility = Visibility.Visible; ImageView.Visibility = Visibility.Collapsed; UploadButton.IsEnabled = false; AspectRatioSlider.Value = wRatio; ImageCropper.AspectRatio = wRatio; ImageCropper.CropShape = CropShape.Rectangular; await ImageCropper.LoadImageFromFile(file); } else { CropGrid.Visibility = Visibility.Visible; ImageView.Visibility = Visibility.Collapsed; UploadButton.IsEnabled = false; //Helper.ShowNotify("Your photo is not in a acceptable aspect ratio." + // "\r\nYou need to crop it and then you can upload it.", 4500); AspectRatioSlider.Value = DefaultAspectRatio; ImageCropper.AspectRatio = DefaultAspectRatio; ImageCropper.CropShape = CropShape.Rectangular; await ImageCropper.LoadImageFromFile(file); } } catch { } }
private async void MainPage_Loaded(object sender, RoutedEventArgs e) { var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/test.jpg")); await ImageCropper.LoadImageFromFile(file); var itemSource = new List <AspectRatioConfig> { new AspectRatioConfig { Name = "Custom", AspectRatio = -1 }, new AspectRatioConfig { Name = "Square", AspectRatio = 1 }, new AspectRatioConfig { Name = "Landscape(16:9)", AspectRatio = 16d / 9d }, new AspectRatioConfig { Name = "Portrait(9:16)", AspectRatio = 9d / 16d }, new AspectRatioConfig { Name = "4:3", AspectRatio = 4d / 3d }, new AspectRatioConfig { Name = "3:2", AspectRatio = 3d / 2d } }; AspectRatioComboBox.ItemsSource = itemSource; AspectRatioComboBox.DisplayMemberPath = "Name"; AspectRatioComboBox.SelectedValuePath = "AspectRatio"; AspectRatioComboBox.SelectedIndex = 0; AspectRatioComboBox.SelectionChanged += this.AspectRatioComboBox_SelectionChanged; }
private async Task PickImage() { var filePicker = new FileOpenPicker { ViewMode = PickerViewMode.Thumbnail, SuggestedStartLocation = PickerLocationId.PicturesLibrary, FileTypeFilter = { ".png", ".jpg", ".jpeg" } }; var file = await filePicker.PickSingleFileAsync(); if (file != null && _imageCropper != null) { await _imageCropper.LoadImageFromFile(file); } }
public async Task LoadFile(StorageFile file, bool innerCall = false) { if (!innerCall) { OriginalFile = file; } try { EditedFile = await new PhotoHelper().SaveToImage(file, false); AspectRatioSlider.Value = AspectRatio; ImageCropper.AspectRatio = AspectRatio; ShowCropper(innerCall); ImageCropper.CropShape = CropShape.Rectangular; await ImageCropper.LoadImageFromFile(EditedFile); } catch { } }
private async void MainPage_Loaded(object sender, RoutedEventArgs e) { var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/test.jpg")); await ImageCropper.LoadImageFromFile(file); var itemSource = new List<AspectRatioConfig> { new AspectRatioConfig { Name = "Custom", AspectRatio = -1 }, new AspectRatioConfig { Name = "Square", AspectRatio = 1 }, new AspectRatioConfig { Name = "Landscape(16:9)", AspectRatio = 16d / 9d }, new AspectRatioConfig { Name = "Portrait(9:16)", AspectRatio = 9d / 16d }, new AspectRatioConfig { Name = "4:3", AspectRatio = 4d / 3d }, new AspectRatioConfig { Name = "3:2", AspectRatio = 3d / 2d } }; }
private async void SelectFromGalleryButtonClick(object sender, RoutedEventArgs e) { Helper.DontUseTimersAndOtherStuff = true; FileOpenPicker openPicker = new FileOpenPicker(); openPicker.ViewMode = PickerViewMode.Thumbnail; openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; openPicker.FileTypeFilter.Add(".jpg"); openPicker.FileTypeFilter.Add(".bmp"); //openPicker.FileTypeFilter.Add(".gif"); openPicker.FileTypeFilter.Add(".png"); StorageFile imgFile = await openPicker.PickSingleFileAsync(); Helper.DontUseTimersAndOtherStuff = false; if (imgFile != null) { ShowEditor(); ImageCropper.AspectRatio = 1d; ImageCropper.CropShape = UI.Controls.CropShape.Circular; await ImageCropper.LoadImageFromFile(imgFile); } }
public async Task SetFileAsync(StorageFile file) { try { Editing = true; CanCrop = false; LoadingUc.Start(); if (file.IsVideo()) { VideoButton.Visibility = Visibility.Visible; IsVideo = true; FileToUpload = file; ThumbnailFile = await file.GetSnapshotFromD3D(TimeSpan.Zero, true); ThumbnailFile = await new PhotoHelper().SaveToImage(ThumbnailFile, false); double width = 0, height = 0; var decoder = await BitmapDecoder.CreateAsync(await ThumbnailFile.OpenReadAsync()); width = decoder.PixelWidth; height = decoder.PixelHeight; var wRatio = AspectRatioHelper.GetAspectRatioForMedia(width, height); var hRatio = AspectRatioHelper.GetAspectRatioForMedia(height, width); MainCanvas.Visibility = Visibility.Collapsed; AspectRatioSlider.Value = wRatio; ImageCropper.AspectRatio = wRatio; ImageCropper.CropShape = CropShape.Rectangular; await ImageCropper.LoadImageFromFile(ThumbnailFile); CropGrid.Visibility = Visibility.Visible; await Task.Delay(1500); ImageCropper.AspectRatio = DefaultAspectRatio; AspectRatioSlider.Value = DefaultAspectRatio; CanCrop = true; LoadingUc.Stop(); } else { VideoButton.Visibility = Visibility.Collapsed; IsVideo = false; ThumbnailFile = null; BitmapDecoder = null; var editNeeded = false; double width = 0, height = 0; var decoder = await BitmapDecoder.CreateAsync(await file.OpenReadAsync()); width = decoder.PixelWidth; height = decoder.PixelHeight; var wRatio = AspectRatioHelper.GetAspectRatioForMedia(width, height); var hRatio = AspectRatioHelper.GetAspectRatioForMedia(height, width); if (wRatio > 1.91 && wRatio < 0.8) { editNeeded = true; } else { if (hRatio > 1.91 && hRatio < 0.8) { editNeeded = true; } } if (height > width) { editNeeded = true; } //in paeini comment bod FileToUpload = await new PhotoHelper().SaveToImage(file, false); if (!editNeeded) { CropGrid.Visibility = Visibility.Visible; MainCanvas.Visibility = Visibility.Collapsed; AspectRatioSlider.Value = wRatio; ImageCropper.AspectRatio = wRatio; ImageCropper.CropShape = CropShape.Rectangular; await ImageCropper.LoadImageFromFile(file); } else { CropGrid.Visibility = Visibility.Visible; MainCanvas.Visibility = Visibility.Collapsed; AspectRatioSlider.Value = DefaultAspectRatio; ImageCropper.AspectRatio = DefaultAspectRatio; ImageCropper.CropShape = CropShape.Rectangular; await ImageCropper.LoadImageFromFile(file); } //await Task.Delay(1500); CanCrop = true; LoadingUc.Stop(); } } catch { } }
async void ImportFile(StorageFile file) { try { if (Path.GetExtension(file.Path).ToLower() == ".mp4" || Path.GetExtension(file.Path).ToLower() == ".mkv") { IsVideo = true; FileToUpload = file; ThumbnailFile = await file.GetSnapshotFromD3D(TimeSpan.Zero, true); ThumbnailFile = await new PhotoHelper().SaveToImage(ThumbnailFile, false); double width = 0, height = 0; var decoder = await BitmapDecoder.CreateAsync(await ThumbnailFile.OpenReadAsync()); width = decoder.PixelWidth; height = decoder.PixelHeight; var wRatio = AspectRatioHelper.GetAspectRatioForMedia(width, height); var hRatio = AspectRatioHelper.GetAspectRatioForMedia(height, width); MainCanvas.Visibility = /*ImageView.Visibility =*/ Visibility.Collapsed; UploadButton.IsEnabled = false; AspectRatioSlider.Value = wRatio; ImageCropper.AspectRatio = wRatio; ImageCropper.CropShape = CropShape.Rectangular; await ImageCropper.LoadImageFromFile(ThumbnailFile); AspectRatioSlider.Value = DefaultAspectRatio; ImageCropper.AspectRatio = DefaultAspectRatio; //await Task.Delay(2500); //using (var fileStream = await ThumbnailFile.OpenAsync(FileAccessMode.ReadWrite, StorageOpenOptions.None)) // await ImageCropper.SaveAsync(fileStream, BitmapFileFormat.Jpeg); //ThumbnailFile = await new PhotoHelper().SaveToImage(ThumbnailFile, false); //decoder = await BitmapDecoder.CreateAsync(await ThumbnailFile.OpenReadAsync()); //VideoBitmapDecoder = decoder; //CurrentCroppedRectForVideo = ImageCropper.CurrentCroppedRect; //ShowImagePreview(ThumbnailFile); //CropGrid.Visibility = Visibility.Collapsed; //MainCanvas.Visibility = /*ImageView.Visibility =*/ Visibility.Visible; //UploadButton.IsEnabled = true; var editNeeded = false; if (wRatio > 1.91 && wRatio < 0.8) { editNeeded = true; } else { if (hRatio > 1.91 && hRatio < 0.8) { editNeeded = true; } } if (height > width) { editNeeded = true; } if (!editNeeded) { FileToUpload = await new PhotoHelper().SaveToImage(file, false); CropGrid.Visibility = Visibility.Visible; CropGrid.Opacity = 1; MainCanvas.Visibility = /*ImageView.Visibility =*/ Visibility.Collapsed; UploadButton.IsEnabled = false; AspectRatioSlider.Value = wRatio; ImageCropper.AspectRatio = wRatio; ImageCropper.CropShape = CropShape.Rectangular; await ImageCropper.LoadImageFromFile(file); } else { CropGrid.Opacity = 1; CropGrid.Visibility = Visibility.Visible; MainCanvas.Visibility = /*ImageView.Visibility =*/ Visibility.Collapsed; UploadButton.IsEnabled = false; AspectRatioSlider.Value = DefaultAspectRatio; ImageCropper.AspectRatio = DefaultAspectRatio; ImageCropper.CropShape = CropShape.Rectangular; await ImageCropper.LoadImageFromFile(file); } } else { IsVideo = false; ThumbnailFile = null; VideoBitmapDecoder = null; var editNeeded = false; double width = 0, height = 0; var decoder = await BitmapDecoder.CreateAsync(await file.OpenReadAsync()); width = decoder.PixelWidth; height = decoder.PixelHeight; var wRatio = AspectRatioHelper.GetAspectRatioForMedia(width, height); var hRatio = AspectRatioHelper.GetAspectRatioForMedia(height, width); if (wRatio > 1.91 && wRatio < 0.8) { editNeeded = true; } else { if (hRatio > 1.91 && hRatio < 0.8) { editNeeded = true; } } if (height > width) { editNeeded = true; } if (!editNeeded) { //CropGrid.Visibility = Visibility.Collapsed; //ImageView.Visibility = Visibility.Visible; //UploadButton.IsEnabled = true; //ShowImagePreview(file); //in paeini comment bod FileToUpload = await new PhotoHelper().SaveToImage(file, false); CropGrid.Visibility = Visibility.Visible; CropGrid.Opacity = 1; MainCanvas.Visibility = /*ImageView.Visibility =*/ Visibility.Collapsed; UploadButton.IsEnabled = false; AspectRatioSlider.Value = wRatio; ImageCropper.AspectRatio = wRatio; ImageCropper.CropShape = CropShape.Rectangular; await ImageCropper.LoadImageFromFile(file); } else { CropGrid.Opacity = 1; CropGrid.Visibility = Visibility.Visible; MainCanvas.Visibility = /*ImageView.Visibility =*/ Visibility.Collapsed; UploadButton.IsEnabled = false; //Helper.ShowNotify("Your photo is not in a acceptable aspect ratio." + // "\r\nYou need to crop it and then you can upload it.", 4500); AspectRatioSlider.Value = DefaultAspectRatio; ImageCropper.AspectRatio = DefaultAspectRatio; ImageCropper.CropShape = CropShape.Rectangular; await ImageCropper.LoadImageFromFile(file); } //using (var source = new StorageFileImageSource(file)) //using (var renderer = new JpegRenderer(source, JpegOutputColorMode.Yuv420, OutputOption.PreserveAspectRatio)) //{ // var info = await source.GetInfoAsync(); // width = info.ImageSize.Width; // height = info.ImageSize.Height; //} } } catch { } }