/// <summary> /// The callback that actually changes the Style if one was provided /// </summary> /// <param name="depObj">UcImageCropper</param> /// <param name="e">The event args</param> static void OnCropperStyleChanged(DependencyObject depObj, DependencyPropertyChangedEventArgs e) { Style s = e.NewValue as Style; if (s != null) { UcImageCropper uc = (UcImageCropper)depObj; uc.selectCanvForImg.CropperStyle = s; } }
private void btnUploadHeadPortrait_Click(object sender, RoutedEventArgs e) { System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog(); ofd.Filter = "Images|*.png;*.jpg;*.jpeg;*.bmp;*.gif"; List<string> allowableFileTypes = new List<string>(); allowableFileTypes.AddRange(new string[] { ".png", ".jpg", ".jpeg", ".bmp", ".gif" }); if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { if (!ofd.FileName.Equals(String.Empty)) { FileInfo f = new FileInfo(ofd.FileName); if (allowableFileTypes.Contains(f.Extension.ToLower())) { UcImageCropper window = new UcImageCropper(); window.ImageUrl = f.FullName; window.ShowDialog(); ImageSourceConverter converter = new ImageSourceConverter(); try { var imageSource = new BitmapImage(); window.ImageStream.Seek(0, SeekOrigin.Begin); imageSource.BeginInit(); imageSource.CreateOptions = BitmapCreateOptions.IgnoreColorProfile; imageSource.StreamSource = window.ImageStream; imageSource.EndInit(); imgHeadPortrait.Source = imageSource; } catch (Exception ex) { MessageBox.Show(ex.InnerException.ToString()); } } else { MessageBox.Show("Invalid file type"); } } else { MessageBox.Show("You did pick a file to use"); } } }