/// <summary> /// Opens a form that allows to select image of image collection /// and returns the selected image. /// </summary> /// <param name="filename">The filename of image file.</param> /// <returns>Selected image.</returns> public static VintasoftImage SelectImageFromFile(string filename) { // temporary image for image in current file VintasoftImage image; // selected index int index; // create image collection using (ImageCollection images = SelectImageFromFile(filename, out index)) { if (index == -1) { return(null); } // get the selected image image = images[index]; // remove the selected image from image collection images.Remove(image); // if the count of images is more than one if (images.Count > 1) { images.ClearAndDisposeItems(); } } return(image); }
public void Cleaning() { using (ImageCollection images = new ImageCollection()) { images.Add(pathImage + "photo.jpg"); try { try { foreach (VintasoftImage image in images) { ExecuteCommand(new AutoInvertCommand(), image); //invert an image if image is inverted ExecuteCommand(new BorderClearCommand(), image); //clear noise on a border of the image ExecuteCommand(new HalftoneRemovalCommand(), image); //remove halftone from the image ExecuteCommand(new DeskewCommand(), image); // detect the correct orientation of the image ExecuteCommand(new HolePunchRemovalCommand(), image); // remove hole punches on image ExecuteCommand(new LineRemovalCommand(LinesType.Tables), image); //remove tables on image ExecuteCommand(new AutoTextInvertCommand(), image); // invert inverted text regions on an image ExecuteCommand(new DespeckleCommand(), image); // remove noise from the image ExecuteCommand(new BorderRemovalCommand(), image); // remove border around the image } } catch (ImageProcessingException ex) { Console.WriteLine(ex.Message); return; } images.SaveAsync(pathImage + "image.tif"); } finally { images.ClearAndDisposeItems(); } } }
public void DeleteImageFromCollection(ImageCollection imageCollection) { imageCollection.ClearAndDisposeItems(); }
/// <summary> /// Opens a form that allows to select image of image collection /// and returns image collection and selected index. /// </summary> /// <param name="filename">The filename of image file.</param> /// <param name="selectedIndex">Selected index.</param> /// <returns>Image collection.</returns> public static ImageCollection SelectImageFromFile(string filename, out int selectedIndex) { selectedIndex = -1; // create image collection ImageCollection images = new ImageCollection(); DocumentPasswordForm.EnableAuthentication(images); try { try { // add an image file to the image collection images.Add(filename); } catch (Exception e) { DemosTools.ShowErrorMessage(e); return(null); } selectedIndex = 0; // if image file contains more than 1 image if (images.Count > 1) { // create a dialog that allows to select image from multipage image file using (SelectImageForm selectImageForm = new SelectImageForm(images)) { // show the dialog DialogResult result = selectImageForm.ShowDialog(); // if image is selected if (result == DialogResult.OK) { // get the selected index selectedIndex = selectImageForm.SelectedImageIndex; } else { selectedIndex = -1; } } } } finally { DocumentPasswordForm.DisableAuthentication(images); // if image is not selected if (selectedIndex == -1) { // clear and dispose images from the image collection images.ClearAndDisposeItems(); // dispose image collection images.Dispose(); } } return(images); }
/// <summary> /// Reloads images in image collection. /// </summary> /// <param name="filename">The filename.</param> /// <param name="readonlyMode">A value indicating whether file should be opened in readonly mode.</param> private void Reload(string filename, bool readOnlyMode) { _images.ClearAndDisposeItems(); _images.Add(filename, readOnlyMode); }