public bool Start(ICollection <ScannedImage> images) { ProgressTitle = MiscResources.AutoDeskewProgress; Status = new OperationStatus { StatusText = MiscResources.AutoDeskewing, MaxProgress = images.Count }; cancel = false; thread = threadFactory.StartThread(() => { var memoryLimitingSem = new Semaphore(4, 4); Pipeline.For(images).StepParallel(img => { if (cancel) { return(null); } memoryLimitingSem.WaitOne(); Bitmap bitmap = scannedImageRenderer.Render(img); try { if (cancel) { return(null); } var transform = RotationTransform.Auto(bitmap); if (cancel) { return(null); } bitmap = transform.Perform(bitmap); img.SetThumbnail(thumbnailRenderer.RenderThumbnail(bitmap)); // The final pipeline step is pretty fast, so updating progress here is more accurate lock (this) { Status.CurrentProgress += 1; } InvokeStatusChanged(); return(Tuple.Create(img, transform)); } finally { bitmap.Dispose(); memoryLimitingSem.Release(); } }).Step((img, transform) => { img.AddTransform(transform); return(img); }).Run(); Status.Success = !cancel; InvokeFinished(); }); return(true); }
public bool Print(PrinterSettings printerSettings, List <ScannedImage> images, List <ScannedImage> selectedImages) { List <ScannedImage> imagesToPrint; switch (printerSettings.PrintRange) { case PrintRange.AllPages: imagesToPrint = images; break; case PrintRange.Selection: imagesToPrint = selectedImages; break; case PrintRange.SomePages: int start = printerSettings.FromPage - 1; int length = printerSettings.ToPage - start; imagesToPrint = images.Skip(start).Take(length).ToList(); break; default: imagesToPrint = new List <ScannedImage>(); break; } if (imagesToPrint.Count == 0) { return(false); } var printDocument = new PrintDocument(); int i = 0; printDocument.PrintPage += (sender, e) => { var image = imagesToPrint[i].GetImage(); try { var pb = e.PageBounds; if (Math.Sign(image.Width - image.Height) != Math.Sign(pb.Width - pb.Height)) { // Flip portrait/landscape to match output image = new RotationTransform(90).Perform(image); } // Fit the image into the output rect while maintaining its aspect ratio var rect = image.Width / pb.Width < image.Height / pb.Height ? new Rectangle(pb.Left, pb.Top, image.Width * pb.Height / image.Height, pb.Height) : new Rectangle(pb.Left, pb.Top, pb.Width, image.Height * pb.Width / image.Width); e.Graphics.DrawImage(image, rect); } finally { image.Dispose(); } e.HasMorePages = (++i < imagesToPrint.Count); }; printDocument.PrinterSettings = printerSettings; printDocument.Print(); return(true); }
private void UpdatePreviewBox() { if (previewTimer == null) { previewTimer = new Timer((obj) => { if (previewOutOfDate && !working) { working = true; previewOutOfDate = false; var result = RotationTransform.Perform((Bitmap)workingImage.Clone()); try { Invoke(new MethodInvoker(() => { if (pictureBox.Image != null) { pictureBox.Image.Dispose(); } pictureBox.Image = result; })); } catch (ObjectDisposedException) { } working = false; } }, null, 0, 100); } previewOutOfDate = true; }
private void btnRevert_Click(object sender, EventArgs e) { RotationTransform = new RotationTransform(); tbAngle.Value = 0; txtAngle.Text = (tbAngle.Value / 10.0).ToString("G"); UpdatePreviewBox(); }
public FRotate(ChangeTracker changeTracker) { this.changeTracker = changeTracker; InitializeComponent(); RotationTransform = new RotationTransform(); }
public bool Start(ICollection <ScannedImage> images) { ProgressTitle = MiscResources.AutoDeskewProgress; Status = new OperationStatus { StatusText = MiscResources.AutoDeskewing, MaxProgress = images.Count }; RunAsync(() => { var memoryLimitingSem = new Semaphore(4, 4); Pipeline.For(images).StepParallel(img => { if (CancelToken.IsCancellationRequested) { return(null); } memoryLimitingSem.WaitOne(); var bitmap = scannedImageRenderer.Render(img).Result; try { if (CancelToken.IsCancellationRequested) { return(null); } var transform = RotationTransform.Auto(bitmap); if (CancelToken.IsCancellationRequested) { return(null); } bitmap = transform.Perform(bitmap); var thumbnail = thumbnailRenderer.RenderThumbnail(bitmap); lock (img) { img.AddTransform(transform); img.SetThumbnail(thumbnail); } // The final pipeline step is pretty fast, so updating progress here is more accurate lock (this) { Status.CurrentProgress += 1; } InvokeStatusChanged(); return(Tuple.Create(img, transform)); } finally { bitmap.Dispose(); memoryLimitingSem.Release(); } }).Run(); return(!CancelToken.IsCancellationRequested); }); return(true); }
public FRotate(ChangeTracker changeTracker, ThumbnailRenderer thumbnailRenderer) { this.changeTracker = changeTracker; this.thumbnailRenderer = thumbnailRenderer; InitializeComponent(); RotationTransform = new RotationTransform(); }
public bool Start(ICollection <ScannedImage> images) { ProgressTitle = MiscResources.AutoDeskewProgress; Status = new OperationStatus { StatusText = MiscResources.AutoDeskewing, MaxProgress = images.Count }; cancel = false; thread = threadFactory.StartThread(() => { Pipeline.For(images).StepParallel(img => { if (cancel) { return(null); } Bitmap bitmap = img.GetImage(); try { if (cancel) { return(null); } var transform = RotationTransform.Auto(bitmap); if (cancel) { return(null); } bitmap = transform.Perform(bitmap); img.SetThumbnail(thumbnailRenderer.RenderThumbnail(bitmap)); return(Tuple.Create(img, transform)); } finally { bitmap.Dispose(); } }).Step((img, transform) => { img.AddTransform(transform); Status.CurrentProgress++; InvokeStatusChanged(); return(img); }).Run(); Status.Success = !cancel; InvokeFinished(); }); return(true); }
public RotationTransform GetRotationTransform(string tag) { RotationTransform[] tlist = GetComponents <RotationTransform>(); int len = tlist.Length; for (int i = 0; i < len; i++) { RotationTransform curr = tlist[i]; if (curr.tag == tag) { return(curr); } } return(null); }
/// <summary> /// Returns the UV Parameters for the given Texture. /// This function uses the same operations as in FOpenNurbsTranslatorImpl::TranslateMaterialTable(), improvements should be applied to both functions. /// </summary> /// <param name="RhinoTexture"></param> /// <returns></returns> private static FDatasmithFacadeMaterialsUtils.FUVEditParameters GetUVParameter(Texture RhinoTexture) { // Extract texture mapping info FDatasmithFacadeMaterialsUtils.FUVEditParameters UVParameters = new FDatasmithFacadeMaterialsUtils.FUVEditParameters(); // Use cached texture coordinates(channel 0) UVParameters.SetChannelIndex(0); //// Extract the UV tiling, offset and rotation angle from the UV transform matrix Transform RotationTransform, OrthogonalTransform; Vector3d Translation, Scale; RhinoTexture.UvwTransform.DecomposeAffine(out Translation, out RotationTransform, out OrthogonalTransform, out Scale); double RotX, RotY, RotZ; if (!RotationTransform.GetYawPitchRoll(out RotX, out RotY, out RotZ)) { //This is not a valid rotation make sure the angles are at 0; RotX = RotY = RotZ = 0; } else { RotX = FDatasmithRhinoUtilities.RadianToDegree(RotX); RotY = FDatasmithRhinoUtilities.RadianToDegree(RotY); RotZ = FDatasmithRhinoUtilities.RadianToDegree(RotZ); } UVParameters.SetUVTiling((float)Scale.X, (float)Scale.Y); //If the tiling vector is not zero. if (Math.Abs(Scale.X) > float.Epsilon && Math.Abs(Scale.Y) > float.Epsilon) { float UVOffsetX = (float)(Translation.X / Scale.X); float UVOffsetY = (float)-(Translation.Y / Scale.Y + 0.5f - 0.5f / Scale.Y); UVParameters.SetUVOffset(UVOffsetX, UVOffsetY); // V-coordinate is inverted in Unreal } // Rotation angle is reversed because V-axis points down in Unreal while it points up in OpenNurbs UVParameters.SetRotationAngle((float)-RotX); return(UVParameters); }
public async Task RotateFlip(IEnumerable <int> selection, RotateFlipType rotateFlipType) { var images = Images.ElementsAt(selection).ToList(); await Task.Factory.StartNew(() => { foreach (ScannedImage img in images) { lock (img) { var transform = new RotationTransform(rotateFlipType); img.AddTransform(transform); var thumb = img.GetThumbnail(); if (thumb != null) { img.SetThumbnail(transform.Perform(thumb)); } } } }); }
//相机旋转值变化 void OnCameraRotation(RotationTransform self) { EagleEyeMap.SetVisualFieldChanged(); }
public async Task <bool> Print(PrinterSettings printerSettings, List <ScannedImage> images, List <ScannedImage> selectedImages) { List <ScannedImage> imagesToPrint; switch (printerSettings.PrintRange) { case PrintRange.AllPages: imagesToPrint = images; break; case PrintRange.Selection: imagesToPrint = selectedImages; break; case PrintRange.SomePages: int start = printerSettings.FromPage - 1; int length = printerSettings.ToPage - start; imagesToPrint = images.Skip(start).Take(length).ToList(); break; default: imagesToPrint = new List <ScannedImage>(); break; } if (imagesToPrint.Count == 0) { return(false); } var snapshots = imagesToPrint.Select(x => x.Preserve()).ToList(); return(await Task.Factory.StartNew(() => { try { var printDocument = new PrintDocument(); int i = 0; printDocument.PrintPage += (sender, e) => { var image = Task.Factory.StartNew(() => scannedImageRenderer.Render(imagesToPrint[i])).Unwrap().Result; try { var pb = e.PageBounds; if (Math.Sign(image.Width - image.Height) != Math.Sign(pb.Width - pb.Height)) { // Flip portrait/landscape to match output image = new RotationTransform(90).Perform(image); } // Fit the image into the output rect while maintaining its aspect ratio var rect = image.Width / pb.Width < image.Height / pb.Height ? new Rectangle(pb.Left, pb.Top, image.Width *pb.Height / image.Height, pb.Height) : new Rectangle(pb.Left, pb.Top, pb.Width, image.Height *pb.Width / image.Width); e.Graphics.DrawImage(image, rect); } finally { image.Dispose(); } e.HasMorePages = (++i < imagesToPrint.Count); }; printDocument.PrinterSettings = printerSettings; printDocument.Print(); Log.Event(EventType.Print, new EventParams { Name = MiscResources.Print, Pages = snapshots.Count, DeviceName = printDocument.PrinterSettings.PrinterName }); return true; } finally { snapshots.ForEach(s => s.Dispose()); } }, TaskCreationOptions.LongRunning)); }
internal void _UnregTransform(RotationTransform t) { m_RotationTransforms.Remove(t); m_RotationTransformChanged = true; }
protected override void ResetTransform() { RotationTransform = new RotationTransform(); tbAngle.Value = 0; txtAngle.Text = (tbAngle.Value / 10.0).ToString("G"); }
void OnEnable() { model = target as RotationTransform; }
internal void _RegTransform(RotationTransform t) { m_RotationTransforms.Add(t); m_RotationTransformChanged = true; }