private static void HolePunchRemove(RasterImage image, string arguments) { int flags = DemoUtils.JsonStringToInteger(arguments, "flags"); int location = DemoUtils.JsonStringToInteger(arguments, "location"); int minimumHoleCount = DemoUtils.JsonStringToInteger(arguments, "minimumHoleCount"); int maximumHoleCount = DemoUtils.JsonStringToInteger(arguments, "maximumHoleCount"); int minimumHoleWidth = DemoUtils.JsonStringToInteger(arguments, "minimumHoleWidth"); int minimumHoleHeight = DemoUtils.JsonStringToInteger(arguments, "minimumHoleHeight"); int maximumHoleWidth = DemoUtils.JsonStringToInteger(arguments, "maximumHoleWidth"); int maximumHoleHeight = DemoUtils.JsonStringToInteger(arguments, "maximumHoleHeight"); if (image.BitsPerPixel != 1) { ColorResolutionCommand cmdColorRes = new ColorResolutionCommand(ColorResolutionCommandMode.InPlace, 1, RasterByteOrder.Bgr, RasterDitheringMethod.None, ColorResolutionCommandPaletteFlags.Fixed, null); cmdColorRes.Run(image); } HolePunchRemoveCommand cmd = new HolePunchRemoveCommand((HolePunchRemoveCommandFlags)flags, (HolePunchRemoveCommandLocation)location, minimumHoleCount, maximumHoleCount, minimumHoleWidth, minimumHoleHeight, maximumHoleWidth, maximumHoleHeight); cmd.Run(image); }
private void ProcessImage(RasterImage rasterImage) { if (rasterImage.BitsPerPixel == 1) { ColorResolutionCommand cmd = new ColorResolutionCommand(); cmd.BitsPerPixel = 8; cmd.Run(rasterImage); } BCProcessStatus status = _bcrReader.Process(rasterImage); this.rasterImageViewer1.Image = rasterImage; if (status == BCProcessStatus.BlurDetected) { Messager.ShowError(this, "Blur detected in image."); } else if (status == BCProcessStatus.GlareDetected) { Messager.ShowError(this, "Glare detected in image."); } else if (status == BCProcessStatus.Failed) { Messager.ShowError(this, "Failed to recognize image."); } UpdateControls(); }
public ColorResolutionDialog(ColorResolutionCommand ColorResolutionCommand, int BPP) { InitializeComponent(); _ColorResolutionCommand = ColorResolutionCommand; _bPP = BPP; InitializeUI(); }
private void _menuItemAnimationOptimizeColors_Click(object sender, EventArgs e) { try { RasterCommand command = null; ViewerForm activeForm = ActiveViewerForm; ColorResolutionDialog dlg = new ColorResolutionDialog(activeForm.Viewer.Image); dlg.BitsPerPixel = activeForm.Viewer.Image.BitsPerPixel; if (dlg.ShowDialog(this) == DialogResult.OK) { int page = activeForm.Viewer.Image.Page; command = new ColorResolutionCommand(ColorResolutionCommandMode.InPlace, dlg.BitsPerPixel, dlg.Order, dlg.DitheringMethod, dlg.PaletteFlags, null); for (int i = 0; i < activeForm.Viewer.Image.PageCount; ++i) { activeForm.Viewer.Image.Page = i + 1; command.Run(activeForm.Viewer.Image); } activeForm.Viewer.Image.Page = page; } } catch (System.Exception ex) { Messager.Show(this, ex, MessageBoxIcon.Warning); } }
public ColorResolutionDialog(ColorResolutionCommand ColorResolutionCommand, int BPP) { InitializeComponent(); _ColorResolutionCommand = ColorResolutionCommand; _bPP = BPP; //Set command default values InitializeUI(); }
private void ApplyDocumentCleanupCommands(RasterImage image) { try { if (image.BitsPerPixel != 1) { ColorResolutionCommand colorRes = new ColorResolutionCommand(); colorRes.BitsPerPixel = 1; colorRes.Order = image.Order; colorRes.Mode = ColorResolutionCommandMode.InPlace; colorRes.Run(image); } if (_miDocCleanDeskew.Checked) { DeskewCommand cmd = new DeskewCommand(); cmd.FillColor = RasterColor.White; cmd.Flags = DeskewCommandFlags.FillExposedArea; cmd.Run(image); } if (_miDocCleanDespeckle.Checked) { DespeckleCommand cmd = new DespeckleCommand(); cmd.Run(image); } if (_miDocCleanBorderRemove.Checked) { BorderRemoveCommand cmd = new BorderRemoveCommand(); cmd.Flags = BorderRemoveCommandFlags.AutoRemove; cmd.Run(image); } if (_miDocCleanHolePunchRemoval.Checked) { HolePunchRemoveCommand cmd = new HolePunchRemoveCommand(); // try to remove left hole punches cmd.Flags = HolePunchRemoveCommandFlags.UseNormalDetection; cmd.Run(image); // try to remove right hole punches cmd.Flags = HolePunchRemoveCommandFlags.UseNormalDetection | HolePunchRemoveCommandFlags.UseLocation; cmd.Location = HolePunchRemoveCommandLocation.Right; cmd.Run(image); } } catch (Exception ex) { Messager.ShowError(this, ex); } }
/// <summary> /// Optimizing the Image to 8 bpp, and Rotating the Image using GetRow and SetRowColumn methods /// </summary> private void _miBasicFeaturesGetSetRow_Click(object sender, EventArgs e) { try { // convert the image to 8 bpp ColorResolutionCommand colorResCommand = new ColorResolutionCommand(); colorResCommand.BitsPerPixel = 8; colorResCommand.DitheringMethod = RasterDitheringMethod.FloydStein; colorResCommand.PaletteFlags = ColorResolutionCommandPaletteFlags.Optimized; colorResCommand.Mode = ColorResolutionCommandMode.InPlace; colorResCommand.Order = RasterByteOrder.Bgr; colorResCommand.SetPalette(null); colorResCommand.Run(_viewer.Image); _viewer.Refresh(); // the row number int outRow = _viewer.Image.Width - 1; // the column number int outCol = 0; // Allocate the buffer. byte[] buffer = new byte[_viewer.Image.BytesPerLine]; // the temp image to save the rotated image (8 bpp, and Height*Width). RasterImage tmpImg = new RasterImage(RasterMemoryFlags.Conventional, _viewer.Image.Height, _viewer.Image.Width, 8, _viewer.Image.Order, _viewer.Image.ViewPerspective, _viewer.Image.GetPalette(), IntPtr.Zero, 0); for (int i = 0; i < _viewer.Image.Height; i++) { _viewer.Image.Access(); _viewer.Image.GetRow(i, buffer, 0, _viewer.Image.BytesPerLine); // loop into the image for (int j = 0; j < tmpImg.Height; j++) { // set the row as column tmpImg.SetRowColumn(outRow, outCol, buffer, j, 1); // move to the next row outRow--; } // move to the next column outCol++; // reset the row number outRow = _viewer.Image.Width - 1; } // set the rotated image into the viewer _viewer.Image = tmpImg; _viewer.Image.Release(); } catch (Exception ex) { Messager.ShowError(this, ex); } }
private RasterImage PrepareOmrImage(RasterImage omrImage) { var colorResolution = new ColorResolutionCommand { BitsPerPixel = 1, DitheringMethod = Leadtools.RasterDitheringMethod.None, PaletteFlags = Leadtools.ImageProcessing.ColorResolutionCommandPaletteFlags.Fixed }; colorResolution.Run(omrImage); LineRemoveCommand(LineRemoveCommandType.Horizontal, omrImage); LineRemoveCommand(LineRemoveCommandType.Vertical, omrImage); return(omrImage); }
private static void FillSeriesThumbnail(LoadSeriesEventArgs e, SeriesInformation seriesInfo) { if (e.LoadedSeries.Streamer.SeriesCells.Length > 0) { MedicalViewerMultiCell cell = e.LoadedSeries.Streamer.SeriesCells[0]; if (cell.VirtualImage != null) { if (cell.VirtualImage[cell.ActiveSubCell].ImageExist) { using (RasterImage image = cell.VirtualImage[cell.ActiveSubCell].Image.Clone()) { Image thumbImage; if (image.Width != 64 || image.Height != 64) { SizeCommand sizeCommand; sizeCommand = new SizeCommand(64, 64, RasterSizeFlags.None); sizeCommand.Run(image); } if (image.BitsPerPixel != 24) { ColorResolutionCommand colorRes = new ColorResolutionCommand(ColorResolutionCommandMode.InPlace, 24, RasterByteOrder.Bgr, RasterDitheringMethod.None, ColorResolutionCommandPaletteFlags.FastMatch, null); colorRes.Run(image); } thumbImage = RasterImageConverter.ConvertToImage(image, ConvertToImageOptions.InitAlpha); seriesInfo.Thumbnail = thumbImage; } } } } }
protected virtual bool DoEffect(ref RasterImage effectedImage) { try { ColorResolutionCommand command = new ColorResolutionCommand(ColorResolutionCommandMode.InPlace, _tempBitsPerPixel, _tempOrder, _tempDitheringMethod, _tempPaletteFlags, null); command.Progress += new EventHandler <RasterCommandProgressEventArgs>(command_Progress); command.Run(effectedImage); _pbProgress.Value = 0; } catch (Exception ex) { throw ex; } return(true); }
private RasterImage AddTextFooter(RasterImage image, string tag, int footerMaxHeight) { LeadRect bounds = LeadRect.Create(0, 0, image.Width, image.Height); using (var imageTag = CreateTextFooter(LeadSize.Create(bounds.Width, footerMaxHeight), tag)) { bounds.Height += imageTag.Height; var bpp = 24; var byteOrder = RasterByteOrder.Bgr; var viewPerspective = RasterViewPerspective.TopLeft; if (image.ViewPerspective != viewPerspective) { image.ChangeViewPerspective(viewPerspective); } if (image.BitsPerPixel != bpp || image.Order != byteOrder) { var colorResCommand = new ColorResolutionCommand( ColorResolutionCommandMode.InPlace, bpp, byteOrder, RasterDitheringMethod.None, ColorResolutionCommandPaletteFlags.Optimized, null); colorResCommand.Run(image); } RasterImage imageResult = new RasterImage(RasterMemoryFlags.Conventional, bounds.Width, bounds.Height, bpp, byteOrder, viewPerspective, null, null, 0); { var combine = new CombineFastCommand(imageResult, bounds, LeadPoint.Create(0, 0), CombineFastCommandFlags.SourceCopy); combine.Run(image); } { var combine = new CombineFastCommand(imageResult, LeadRect.Create(bounds.X, image.Height, bounds.Width, bounds.Height - image.Height), LeadPoint.Create(0, 0), CombineFastCommandFlags.SourceCopy); combine.Run(imageTag); } return(imageResult); } }
public override void SetImageData(AnnContainer container, LeadRectD bounds, byte[] data) { if (_image == null) { return; } using (var ms = new MemoryStream(data)) { using (var codecs = new RasterCodecs()) { using (var image = codecs.Load(ms)) { if (image.ViewPerspective != _image.ViewPerspective) { image.ChangeViewPerspective(_image.ViewPerspective); } if (image.BitsPerPixel != _image.BitsPerPixel || image.Order != _image.Order) { var palette = _image.GetPalette(); var paletteFlags = palette != null ? ColorResolutionCommandPaletteFlags.UsePalette : ColorResolutionCommandPaletteFlags.Optimized; var colorResCommand = new ColorResolutionCommand( ColorResolutionCommandMode.InPlace, _image.BitsPerPixel, _image.Order, RasterDitheringMethod.None, paletteFlags, palette); colorResCommand.Run(image); } var combine = new CombineFastCommand(_image, bounds.ToLeadRect(), LeadPoint.Create(0, 0), CombineFastCommandFlags.SourceCopy); combine.Run(image); } } } }
private static void BorderRemove(RasterImage image, string arguments) { int flags = DemoUtils.JsonStringToInteger(arguments, "flags"); int border = DemoUtils.JsonStringToInteger(arguments, "border"); int percent = DemoUtils.JsonStringToInteger(arguments, "percent"); int whiteNoiseLength = DemoUtils.JsonStringToInteger(arguments, "whiteNoiseLength"); int variance = DemoUtils.JsonStringToInteger(arguments, "variance"); if (image.BitsPerPixel != 1) { ColorResolutionCommand cmdColorRes = new ColorResolutionCommand(ColorResolutionCommandMode.InPlace, 1, RasterByteOrder.Bgr, RasterDitheringMethod.None, ColorResolutionCommandPaletteFlags.Fixed, null); cmdColorRes.Run(image); } if ((BorderRemoveBorderFlags)border == BorderRemoveBorderFlags.None) { border = (int)(new BorderRemoveCommand()).Border; } BorderRemoveCommand cmd = new BorderRemoveCommand((BorderRemoveCommandFlags)flags, (BorderRemoveBorderFlags)border, percent, whiteNoiseLength, variance); cmd.Run(image); }
/// <summary> /// Batch 1 Functions /// </summary> private void DoBatch1() { // save the current caption string tmpCaption = Text; // change cursor Cursor = Cursors.SizeNS; // disable the form Enabled = false; // Do Color Resolution Text = "Optimizing Image To 8 Bits Per Pixel With Burkes Dithering..."; ColorResolutionCommand colorResCommand = new ColorResolutionCommand(); colorResCommand.BitsPerPixel = 8; colorResCommand.DitheringMethod = RasterDitheringMethod.Burkes; colorResCommand.PaletteFlags = ColorResolutionCommandPaletteFlags.Optimized; colorResCommand.Mode = ColorResolutionCommandMode.InPlace; colorResCommand.Order = RasterByteOrder.Bgr; colorResCommand.SetPalette(null); colorResCommand.Run(_viewer.Image); Text = "Image Is Optimized"; _viewer.Refresh(); Thread.Sleep(2000); // change cursor Cursor = Cursors.SizeWE; // Do Flip Text = "Flipping Image..."; FlipCommand flipCommand = new FlipCommand(); flipCommand.Horizontal = false; flipCommand.Run(_viewer.Image); Text = "Image Is Flipped"; _viewer.Refresh(); Thread.Sleep(2000); // change cursor Cursor = Cursors.SizeNS; // Do Lightening Text = "Lightening Image..."; ChangeIntensityCommand changeIntensityCommand = new ChangeIntensityCommand(); changeIntensityCommand.Brightness = 200; changeIntensityCommand.Run(_viewer.Image); Text = "Image Is Lightened"; _viewer.Refresh(); Thread.Sleep(2000); // change cursor Cursor = Cursors.SizeWE; // Do Resize Text = "Resizing Image..."; ResizeCommand resizeCommand = new ResizeCommand(); resizeCommand.Flags = RasterSizeFlags.None; resizeCommand.DestinationImage = new RasterImage(RasterMemoryFlags.Conventional, (_viewer.Image.Width + 1) / 2, (_viewer.Image.Height + 1) / 2, _viewer.Image.BitsPerPixel, _viewer.Image.Order, _viewer.Image.ViewPerspective, _viewer.Image.GetPalette(), IntPtr.Zero, 0); resizeCommand.Run(_viewer.Image); _viewer.Image = resizeCommand.DestinationImage; Text = "Image Is Resized"; _viewer.Refresh(); Thread.Sleep(2000); Cursor = Cursors.SizeNS; // Do Rotate Text = "Rotating Image..."; RotateCommand rotateCommand = new RotateCommand(); rotateCommand.Angle = -4500; rotateCommand.FillColor = new RasterColor(255, 0, 0); rotateCommand.Flags = RotateCommandFlags.None; rotateCommand.Run(_viewer.Image); Text = "Image Is Rotated, Batch Is Complete"; _viewer.Refresh(); Thread.Sleep(2000); // change the cursor to arrow Cursor = Cursors.Arrow; // return the old caption Text = tmpCaption; // enable the form Enabled = true; }
void _printDocument_PrintPage(object sender, PrintPageEventArgs e) { try { using (RasterImage _img = _CurrCell.Image.CloneAll()) { ColorResolutionCommand colorResolutionCommand = new ColorResolutionCommand(ColorResolutionCommandMode.InPlace, _img.BitsPerPixel, _img.Order, _img.DitheringMethod, ColorResolutionCommandPaletteFlags.None, null); colorResolutionCommand.Run(_img); // Get the print document object PrintDocument document = sender as PrintDocument; if (!AutoPageSettings)//Nếu lấy cấu hình in từ tùy chọn Cấu hình in lazer thì cần thiết lập lại một số thông số cho đối tượng in { PageSettings ps = Getps(); document.PrinterSettings.DefaultPageSettings.Margins = ps.Margins; document.PrinterSettings.DefaultPageSettings.PaperSize = ps.PaperSize; document.PrinterSettings.DefaultPageSettings.Landscape = ps.Landscape; } document.PrinterSettings.PrinterName = _LazerPrinterName; // Create an new LEADTOOLS image printer class RasterImagePrinter printer = new RasterImagePrinter(); // Set the document object so page calculations can be performed printer.PrintDocument = document; // We want to fit and center the image into the maximum print area printer.SizeMode = RasterPaintSizeMode.FitAlways; printer.HorizontalAlignMode = RasterPaintAlignMode.Center; printer.VerticalAlignMode = RasterPaintAlignMode.Center; // Account for FAX images that may have different horizontal and vertical resolution printer.UseDpi = true; // Print the whole image printer.ImageRectangle = Rectangle.Empty; // Use maximum page dimension ignoring the margins, this will be equivalant of printing // using Windows Photo Gallery printer.PageRectangle = RectangleF.Empty; printer.UseMargins = false; // Print the current page printer.Print(_img, _img.Page, e); // Inform the printer we have no more pages to print e.HasMorePages = false; } } catch (Exception ex) { Utility.ShowMsg("Lỗi khi đẩy dữ liệu ảnh ra máy in:\n" + ex.Message, "Thông báo lỗi"); } }
private void buttonScreenCapture_Click(object sender, EventArgs e) { if (_tsUseHotkey.Checked && !showMessagebox) { MyMessageBox myMessageBox = new MyMessageBox("Hotkey Capture", "Press F11 to start capture"); myMessageBox.Show(this); showMessagebox = myMessageBox.Checked; } EnableUI(false); System.Threading.Thread.Sleep(500); try { // Capture an area from the screen RasterImage image = DoCapture(_tsUseHotkey.Checked); this.BringToFront(); ColorResolutionCommand colorRes = new ColorResolutionCommand(ColorResolutionCommandMode.InPlace, 24, RasterByteOrder.Bgr, RasterDitheringMethod.None, ColorResolutionCommandPaletteFlags.Fixed, null); colorRes.Run(image); EnableUI(true); if (image != null) { ClearDocument(); ClearImage(); // Store the new image _imageViewer.Image = image; // Set the image to the PictureBox UpdateViewer(); // OCR the image and get back an RTF file string document = DoOcr(_imageViewer.Image); if (!string.IsNullOrEmpty(document)) { var options = new LoadDocumentOptions() { UseCache = false }; // Load the RTF file var doc = DocumentFactory.LoadFromFile(document, options); doc.AutoDisposeDocuments = true; _svgViewer.SetDocument(doc); _svgViewer.Commands.Run(DocumentViewerCommands.ViewFitPage); } } } catch (Exception ex) { RasterException rasex = ex as RasterException; if (rasex != null) { if (rasex.Code != RasterExceptionCode.UserAbort) { Messager.ShowError(this, ex); } } else { Messager.ShowError(this, ex); } } finally { EnableUI(true); } }
private void _miEditPaste_Click(object sender, EventArgs e) { try { using (WaitCursor wait = new WaitCursor()) { RasterImage image = RasterClipboard.Paste(this.Handle); if (image != null) { ViewerForm activeForm = ActiveViewerForm; if (image.HasRegion && activeForm == null) { image.MakeRegionEmpty(); } if (image.HasRegion) { // make sure the images have the same BitsPerPixel and Palette if (activeForm.Viewer.Image.BitsPerPixel > 8) { if (image.BitsPerPixel != activeForm.Viewer.Image.BitsPerPixel) { try { ColorResolutionCommand colorRes = new ColorResolutionCommand(); colorRes.BitsPerPixel = activeForm.Viewer.Image.BitsPerPixel; colorRes.Order = activeForm.Viewer.Image.Order; colorRes.Mode = Leadtools.ImageProcessing.ColorResolutionCommandMode.InPlace; colorRes.Run(image); } catch (Exception ex) { Messager.ShowError(this, ex); } } } else { try { ColorResolutionCommand colorRes = new ColorResolutionCommand(); colorRes.BitsPerPixel = activeForm.Viewer.Image.BitsPerPixel; colorRes.SetPalette(activeForm.Viewer.Image.GetPalette()); colorRes.PaletteFlags = Leadtools.ImageProcessing.ColorResolutionCommandPaletteFlags.UsePalette; colorRes.Mode = Leadtools.ImageProcessing.ColorResolutionCommandMode.InPlace; colorRes.Run(image); } catch (Exception ex) { Messager.ShowError(this, ex); } } } else { NewImage(new ImageInformation(image)); } } } } catch (Exception ex) { Messager.ShowError(this, ex); } finally { UpdateControls(); } }
public ColorResolutionDialog() { InitializeComponent(); _ColorResolutionCommand = new ColorResolutionCommand(); InitializeUI(); }