private void SaveCropButton_OnClick(object sender, RoutedEventArgs e) { var rect = _croppingAdorner.ClippingRectangle; var xRatio = rect.X / ImageHolder.ActualWidth; var yRatio = rect.Y / ImageHolder.ActualHeight; var widthRatio = rect.Width / ImageHolder.ActualWidth; var heightRatio = rect.Height / ImageHolder.ActualHeight; Rect = rect; var originalImg = (Bitmap)Bitmap.FromFile(CropResult); var result = CropToShape.KiCut(originalImg, (float)xRatio * originalImg.Width, (float)yRatio * originalImg.Height, (float)widthRatio * originalImg.Width, (float)heightRatio * originalImg.Height); CropResult = StoragePath.GetPath("crop-" + DateTime.Now.GetHashCode() + "-" + Guid.NewGuid().ToString().Substring(0, 7)); result.Save(CropResult); CropResultThumbnail = ImageUtil.GetThumbnailFromFullSizeImg(CropResult); IsCropped = true; Close(); }
private void RotateFlipImg(RotateFlipType roatateFlipType) { var img = (Bitmap)Bitmap.FromFile(CropResult); img.RotateFlip(roatateFlipType); String rotatedImg = StoragePath.GetPath("rotated-" + DateTime.Now.GetHashCode() + "-" + Guid.NewGuid().ToString().Substring(0, 7)); img.Save(rotatedImg); CropResult = rotatedImg; RotateResult = rotatedImg; thumbnailImageFile.Text = ImageUtil.GetThumbnailFromFullSizeImg(rotatedImg); CropResultThumbnail = ImageUtil.GetThumbnailFromFullSizeImg(rotatedImg); IsRotated = true; //Resize the ImageHolder and Window after rotating if (roatateFlipType.Equals(RotateFlipType.Rotate270FlipNone) || roatateFlipType.Equals(RotateFlipType.Rotate90FlipNone)) { ImageHolder.Width = ImageHolder.ActualHeight / Bitmap.FromFile(CropResultThumbnail).Height *Bitmap.FromFile(CropResultThumbnail).Width; ImageHolder.Height = ImageHolder.ActualHeight; this.Width = ImageHolder.Width + 20; this.CenterWindowOnScreen(); } Dispatcher.Invoke(DispatcherPriority.SystemIdle, new Action(() => { var rect = AutoFit(); _croppingAdorner.ClippingRectangle = rect; })); }
/// <summary> /// Add image by downloading /// </summary> /// <param name="downloadLink"></param> /// <param name="contentSlide"></param> /// <param name="slideWidth"></param> /// <param name="slideHeight"></param> public void AddImageSelectionListItem(string downloadLink, Slide contentSlide, float slideWidth, float slideHeight) { if (StringUtil.IsEmpty(downloadLink) || !UrlUtil.IsUrlValid(downloadLink)) // Case 1: If url not valid { View.ShowErrorMessageBox(TextCollection.PictureSlidesLabText.ErrorUrlLinkIncorrect); return; } var item = new ImageItem { ImageFile = StoragePath.LoadingImgPath, ContextLink = downloadLink }; UrlUtil.GetMetaInfo(ref downloadLink, item); ImageSelectionList.Add(item); IsActiveDownloadProgressRing.Flag = true; var imagePath = StoragePath.GetPath("img-" + DateTime.Now.GetHashCode() + "-" + Guid.NewGuid().ToString().Substring(0, 7)); ImageDownloader .Get(downloadLink, imagePath) .After(() => { try { VerifyIsProperImage(imagePath); // Case 2: not a proper image item.UpdateDownloadedImage(imagePath); if (ImageSelectionListSelectedItem.ImageItem != null && imagePath == ImageSelectionListSelectedItem.ImageItem.ImageFile) { UpdatePreviewImages(ImageSelectionListSelectedItem.ImageItem, contentSlide, slideWidth, slideHeight); } } catch { View.ShowErrorMessageBox(TextCollection.PictureSlidesLabText.ErrorImageDownloadCorrupted); ImageSelectionList.Remove(item); } finally { IsActiveDownloadProgressRing.Flag = false; } }) // Case 3: Possibly network timeout .OnError(e => { IsActiveDownloadProgressRing.Flag = false; ImageSelectionList.Remove(item); View.ShowErrorMessageBox(TextCollection.PictureSlidesLabText.ErrorFailedToLoad + e.Message); }) .Start(); }
public void TestStoragePathInit() { try { StoragePath.GetPath("some-name"); Assert.Fail(); } catch (Exception) { } }
private static string ExtractPictureInfo(Shape originalImageShape) { var fullsizeImageFile = StoragePath.GetPath("img-" + DateTime.Now.GetHashCode() + Guid.NewGuid().ToString().Substring(0, 7) + ".jpg"); // need to make shape visible so that can export originalImageShape.Visible = MsoTriState.msoTrue; originalImageShape.Export(fullsizeImageFile, PpShapeFormat.ppShapeFormatJPG); originalImageShape.Visible = MsoTriState.msoFalse; return(fullsizeImageFile); }
private static ImageItem ExtractImageItem(Shape originalImageShape, List <Shape> croppedShapeList) { var fullsizeImageFile = StoragePath.GetPath("img-" + DateTime.Now.GetHashCode() + Guid.NewGuid().ToString().Substring(0, 7) + ".jpg"); // need to make shape visible so that can export originalImageShape.Visible = MsoTriState.msoTrue; originalImageShape.Export(fullsizeImageFile, PpShapeFormat.ppShapeFormatJPG); originalImageShape.Visible = MsoTriState.msoFalse; var fullsizeThumbnailFile = ImageUtil.GetThumbnailFromFullSizeImg(fullsizeImageFile); var croppedImageFile = StoragePath.GetPath("crop-" + DateTime.Now.GetHashCode() + Guid.NewGuid().ToString().Substring(0, 7) + ".jpg"); string croppedThumbnailFile; var croppedImageShape = croppedShapeList.Count > 0 ? croppedShapeList[0] : null; if (croppedImageShape != null) { croppedImageShape.Visible = MsoTriState.msoTrue; croppedImageShape.Export(croppedImageFile, PpShapeFormat.ppShapeFormatJPG); croppedThumbnailFile = ImageUtil.GetThumbnailFromFullSizeImg(croppedImageFile); croppedImageShape.Visible = MsoTriState.msoFalse; } else { croppedImageFile = null; croppedThumbnailFile = null; } var rect = new Rect(); rect.X = double.Parse(originalImageShape.Tags[Service.Effect.Tag.ReloadRectX]); rect.Y = double.Parse(originalImageShape.Tags[Service.Effect.Tag.ReloadRectY]); rect.Width = double.Parse(originalImageShape.Tags[Service.Effect.Tag.ReloadRectWidth]); rect.Height = double.Parse(originalImageShape.Tags[Service.Effect.Tag.ReloadRectHeight]); var imageItem = new ImageItem { ImageFile = fullsizeThumbnailFile, FullSizeImageFile = fullsizeImageFile, Tooltip = ImageUtil.GetWidthAndHeight(fullsizeImageFile), CroppedImageFile = croppedImageFile, CroppedThumbnailImageFile = croppedThumbnailFile, ContextLink = originalImageShape.Tags[Service.Effect.Tag.ReloadImgContext], Rect = rect }; return(imageItem); }
public void TestStoragePathInit2() { try { StoragePath.InitPersistentFolder(); StoragePath.CleanPersistentFolder(new List <string>()); StoragePath.GetPath("some-name"); } catch (Exception) { Assert.Fail(); } }
private string CropAndSaveImageFromFile(string image, double xRatio, double yRatio, double widthRatio, double heightRatio) { Bitmap originalImg = (Bitmap)Bitmap.FromFile(image); Bitmap result = CropToShape.KiCut(originalImg, (float)xRatio * originalImg.Width, (float)yRatio * originalImg.Height, (float)widthRatio * originalImg.Width, (float)heightRatio * originalImg.Height); string croppedImage = StoragePath.GetPath("crop-" + DateTime.Now.GetHashCode() + "-" + Guid.NewGuid().ToString().Substring(0, 7)); result.Save(croppedImage); return(croppedImage); }
private static string ExtractCroppedPicture(List <Shape> croppedShapeList) { var croppedImageFile = StoragePath.GetPath("crop-" + DateTime.Now.GetHashCode() + Guid.NewGuid().ToString().Substring(0, 7) + ".jpg"); var croppedImageShape = croppedShapeList.Count > 0 ? croppedShapeList[0] : null; if (croppedImageShape != null) { croppedImageShape.Visible = MsoTriState.msoTrue; croppedImageShape.Export(croppedImageFile, PpShapeFormat.ppShapeFormatJPG); croppedImageShape.Visible = MsoTriState.msoFalse; } else { croppedImageFile = null; } return(croppedImageFile); }
/// <summary> /// Add image by downloading /// </summary> /// <param name="downloadLink"></param> /// <param name="contentSlide"></param> /// <param name="slideWidth"></param> /// <param name="slideHeight"></param> public void AddImageSelectionListItem(string downloadLink, Slide contentSlide, float slideWidth, float slideHeight) { if (StringUtil.IsEmpty(downloadLink) || !UrlUtil.IsUrlValid(downloadLink)) // Case 1: If url not valid { View.ShowErrorMessageBox(PictureSlidesLabText.ErrorUrlLinkIncorrect); Logger.Log("Url link error when add internet image"); return; } var item = new ImageItem { ImageFile = StoragePath.LoadingImgPath, ContextLink = downloadLink, Source = downloadLink }; UrlUtil.GetMetaInfo(ref downloadLink, item); ImageSelectionList.Add(item); IsActiveDownloadProgressRing.Flag = true; var imagePath = StoragePath.GetPath("img-" + DateTime.Now.GetHashCode() + "-" + Guid.NewGuid().ToString().Substring(0, 7)); ImageDownloader .Get(downloadLink, imagePath) .After((AutoUpdate.Downloader.AfterDownloadEventDelegate)(() => { try { Logger.Log("Add internet picture begins"); VerifyIsProperImage(imagePath); // Case 2: not a proper image item.UpdateDownloadedImage(imagePath); UpdatePictureInPictureVariationWhenAddedNewOne(item); if (ImageSelectionListSelectedItem.ImageItem != null && imagePath == ImageSelectionListSelectedItem.ImageItem.FullSizeImageFile) { UpdatePreviewImages(ImageSelectionListSelectedItem.ImageItem, contentSlide, slideWidth, slideHeight); } else if (IsInPictureVariation()) { UpdatePreviewImages( ImageSelectionListSelectedItem.ImageItem ?? View.CreateDefaultPictureItem(), contentSlide, slideWidth, slideHeight); } Logger.Log("Add internet picture ends"); } catch (Exception e) { View.ShowErrorMessageBox(PictureSlidesLabText.ErrorImageDownloadCorrupted); ImageSelectionList.Remove(item); Logger.LogException(e, "AddImageSelectionListItem (download)"); } finally { IsActiveDownloadProgressRing.Flag = false; } })) // Case 3: Possibly network timeout .OnError((AutoUpdate.Downloader.ErrorEventDelegate)(e => { IsActiveDownloadProgressRing.Flag = false; ImageSelectionList.Remove(item); View.ShowErrorMessageBox(PictureSlidesLabText.ErrorFailedToLoad + e.Message); })) .Start(); }