/// <summary> /// Rotates focused image with annotations. /// </summary> /// <param name="annotationViewer">The annotation viewer.</param> /// <param name="rotationAngle">Rotation angle in degrees.</param> /// <param name="borderColorType">Border color type.</param> /// <param name="pixelFormat">New pixel format.</param> private static void RotateFocusedImageWithAnnotations(AnnotationViewer annotationViewer, float rotationAngle, BorderColorType borderColorType, PixelFormat pixelFormat) { // if pixel formats are not equal if (pixelFormat != annotationViewer.Image.PixelFormat) { // change pixel format ChangePixelFormatCommand command = new ChangePixelFormatCommand(pixelFormat); command.ExecuteInPlace(annotationViewer.Image); } // rotate the focused image with annotations annotationViewer.RotateImageWithAnnotations(rotationAngle, borderColorType); }
/// <summary> /// Recognizes barcodes synchronously. /// </summary> public void ReadBarcodesSync() { if (_isRecognitionStarted) { throw new InvalidOperationException("Recognition process is executing at this moment."); } _isRecognitionStarted = true; if (InvokeRequired) { Invoke(new OnRecoginitionStartedDelegate(OnRecoginitionStarted), EventArgs.Empty); } else { OnRecoginitionStarted(EventArgs.Empty); } try { #if !REMOVE_BARCODE_SDK if (ImageViewer != null) { VintasoftImage image = ImageViewer.Image; if (image != null) { ChangePixelFormatCommand convertCommand = null; switch (image.PixelFormat) { case PixelFormat.Gray16: convertCommand = new ChangePixelFormatCommand(PixelFormat.Gray8); break; } if (convertCommand != null) { image = convertCommand.Execute(image); } // set settings if (Rectangle.Size.IsEmpty) { ReaderSettings.ScanRectangle = Rectangle.Empty; } else { ReaderSettings.ScanRectangle = Rectangle; } // recognize barcodes using (Image bitmap = image.GetAsBitmap()) RecognitionResults = _reader.ReadBarcodes(bitmap); if (convertCommand != null) { image.Dispose(); } } else { RecognitionResults = null; } } else { RecognitionResults = null; } #endif } catch (Exception ex) { DemosTools.ShowErrorMessage(ex); } finally { _isRecognitionStarted = false; _isAsyncRecognitionStarted = false; if (InvokeRequired) { Invoke(new OnRecoginitionFinishedDelegate(OnRecoginitionFinished), EventArgs.Empty); } else { OnRecoginitionFinished(EventArgs.Empty); } } }