private void Rotate(ImageFactory imageFactory, ProcessingParameters parameters) { if (parameters.RotationAngle == 0) { return; } imageFactory.Rotate(parameters.RotationAngle); }
private void Resize(ImageFactory imageFactory, ProcessingParameters parameters) { if (parameters.ScaleX == 1 && parameters.ScaleY == 1) { return; } var size = new Size((int)(imageFactory.Image.Width * parameters.ScaleX), (int)(imageFactory.Image.Height * parameters.ScaleY)); var resizeLayer = new ResizeLayer(size, ResizeMode.Stretch); imageFactory.Resize(resizeLayer); }
public Bitmap ProcessImage(Bitmap image, ProcessingParameters parameters) { using (var imageFactory = new ImageFactory(preserveExifData: true)) { using (var stream = new MemoryStream()) { image.Save(stream, ImageFormat.Png); imageFactory.Load(stream); Resize(imageFactory, parameters); Crop(imageFactory, parameters); Rotate(imageFactory, parameters); imageFactory.Save(stream); var result = new Bitmap(stream); return(result); } } }
/// <summary> /// Выполняет один тест чтения скрываемого текста при искажении с указанными параметрами и возвращает его результат /// </summary> /// <param name="sourceImagePath">Путь к исходному изображению</param> /// <param name="fullContainer">Заполненный контейнер</param> /// <param name="hiddenText"></param> /// <param name="encoder"></param> /// <param name="parameters"></param> /// <param name="saveProcessed"></param> /// <returns></returns> private RobustnessTestResult RunSingleTest(string sourceImagePath, Bitmap fullContainer, string hiddenText, IEncoder encoder, ProcessingParameters parameters, bool saveProcessed = true) { var processedImage = processor.ProcessImage(fullContainer, parameters); var result = new RobustnessTestResult() { Parameters = parameters, SourceImagePath = sourceImagePath }; if (saveProcessed) { var processedPath = Path.Combine( Path.GetDirectoryName(sourceImagePath), "Processed", string.Format("{0}_{1}{2}", Path.GetFileNameWithoutExtension(sourceImagePath), GetTimeStamp(), Path.GetExtension(sourceImagePath)) ); processedImage.Save(processedPath); result.ProcessedImagePath = processedPath; } result.ErrorRateTransformed = errorEstimator.EstimateBitErrorRate(hiddenText, processedImage, encoder); return(result); }