// Don't forget to Dispose ImagXpress void Dispose() { if (!(imagXpress1 == null)) { imagXpress1.Dispose(); imagXpress1 = null; } if (!(imagProcessor == null)) { imagProcessor.Dispose(); imagProcessor = null; } if (!(imagX1 == null)) { imagX1.Dispose(); imagX1 = null; } }
public void Process() { bool imageOpened = false; int TryCount = 0; while ((!imageOpened) && (TryCount < 25)) { try { //Create the image object and open the image myImage = Accusoft.ImagXpressSdk.ImageX.FromFile(daImagXpress, myImageFileName); imageOpened = true; } catch (ImagXpressException ex) { ChangeLabelText("Error opening image - " + ex.Number.ToString() + ". Retrying..."); } TryCount++; } if (TryCount >= 25) { throw new Exception("Unable to open the image for processing."); } //Rest System.Threading.Thread.Sleep(10); try { //Create the processor object and tie it to the image we just opened myProcessor = new Accusoft.ImagXpressSdk.Processor(daImagXpress, myImage); } catch (ImagXpressException ex) { AccusoftError(ex); } //Rest System.Threading.Thread.Sleep(10); try { //Set the viewer's image object equal to the one we are operating on... //we have to do this each time the image changes because we are making //copies of the image each time ChangeImage(myImage); //Set the viewing zoom type ChangeZoomToFitType(Accusoft.ImagXpressSdk.ZoomToFitType.FitBest); } catch (ImagXpressException ex) { AccusoftError(ex); } //Rest System.Threading.Thread.Sleep(10); //Change the viewer's label. ChangeLabelText("Processing..."); //Rest System.Threading.Thread.Sleep(10); //Change the viewer's label. ChangeLabelText("Resizing..."); try { //Resize the image myProcessor.Resize(new System.Drawing.Size(myImage.ImageXData.Width * (myResize), myImage.ImageXData.Height * myResize), Accusoft.ImagXpressSdk.ResizeType.Quality); } catch (ImagXpressException ex) { AccusoftError(ex); } //Rest System.Threading.Thread.Sleep(10); try { //Set the viewer's image object equal to the one we are operating on... //we have to do this each time the image changes because we are making //copies of the image each time ChangeImage(myImage); } catch (ImagXpressException ex) { AccusoftError(ex); } //Rest System.Threading.Thread.Sleep(10); //Change the viewer's label. ChangeLabelText("Blurring..."); try { //Resize the image myProcessor.Blur(); } catch (ImagXpressException ex) { AccusoftError(ex); } //Rest System.Threading.Thread.Sleep(10); try { //Set the viewer's image object equal to the one we are operating on... //we have to do this each time the image changes because we are making //copies of the image each time ChangeImage(myImage); } catch (ImagXpressException ex) { AccusoftError(ex); } //Rest System.Threading.Thread.Sleep(10); //Change the viewer's label. ChangeLabelText("Negating..."); try { //Resize the image myProcessor.Negate(); } catch (ImagXpressException ex) { AccusoftError(ex); } //Rest System.Threading.Thread.Sleep(10); try { //Set the viewer's image object equal to the one we are operating on... //we have to do this each time the image changes because we are making //copies of the image each time ChangeImage(myImage); } catch (ImagXpressException ex) { AccusoftError(ex); } //Rest System.Threading.Thread.Sleep(10); //Change the viewer's label. ChangeLabelText("Zooming..."); try { //Set the viewing zoom type ChangeZoomToFitType(Accusoft.ImagXpressSdk.ZoomToFitType.FitWidth); } catch (ImagXpressException ex) { AccusoftError(ex); } //Rest System.Threading.Thread.Sleep(10); try { //Set the viewer's image object equal to the one we are operating on... //we have to do this each time the image changes because we are making //copies of the image each time ChangeImage(myImage); //Set the viewing zoom type ChangeZoomToFitType(Accusoft.ImagXpressSdk.ZoomToFitType.FitBest); } catch (ImagXpressException ex) { AccusoftError(ex); } //Rest System.Threading.Thread.Sleep(10); //Change the viewer's label. ChangeLabelText("(Un)Negating..."); try { //Resize the image myProcessor.Negate(); } catch (ImagXpressException ex) { AccusoftError(ex); } //Rest System.Threading.Thread.Sleep(10); try { //Set the viewer's image object equal to the one we are operating on... //we have to do this each time the image changes because we are making //copies of the image each time ChangeImage(myImage); } catch (ImagXpressException ex) { AccusoftError(ex); } //Rest System.Threading.Thread.Sleep(10); //Change the viewer's label. ChangeLabelText("Processed."); //Rest System.Threading.Thread.Sleep(10); //kill the processor myProcessor.Dispose(); myProcessor = null; //kill the local copy of the image myImage.Dispose(); myImage = null; GC.Collect(); System.Threading.Thread.Sleep(100); }