/// <summary> /// Image preparing process. Resizing and fixing quality. /// </summary> /// <param name="originalImage">Original image</param> /// <param name="preComplementWidth">Width used when resizing</param> /// <returns>Grayscaled image for descewing</returns> private static KrecImage PrepareImageForDeskewing(KrecImage originalImage, out int preComplementWidth) { if (originalImage.HorizontalResolution > maxDpi) { // TODO: make k be integer to avoid resampling errors double k = maxDpi / originalImage.HorizontalResolution; originalImage = ImageSizesModifier.CompressImageToNewSizes(originalImage, (int)Math.Round(originalImage.Width * k), (int)Math.Round(originalImage.Height * k)); } KrecImage projectionImage; preComplementWidth = Math.Min(projectionSideWidth, originalImage.Width); if (originalImage.Height < maxCompletedSideWith && originalImage.Width < maxCompletedSideWith) //имитирует поведение прошлого сжимателя { int dx = (maxCompletedSideWith - originalImage.Width) / 2; int dy = (maxCompletedSideWith - originalImage.Height) / 2; int newWidth = projectionSideWidth - dx; int newHeight = projectionSideWidth - dy; double k = Math.Max((double)originalImage.Height / newHeight, (double)originalImage.Width / newWidth); var compressedImage = ImageSizesModifier.CompressImageToNewSizes(originalImage, (int)(originalImage.Width / k), (int)(originalImage.Height / k)); compressedImage = BitmapProcessor.AlignImageBackround(compressedImage); preComplementWidth = (int)(originalImage.Width / k); projectionImage = ImageSizesModifier.GetImageWithPowerOf2Side(compressedImage, projectionSideWidth); } else { var alignedImage = BitmapProcessor.AlignImageBackround(originalImage); projectionImage = ImageSizesModifier.GetImageWithPowerOf2Side(alignedImage, projectionSideWidth); } return(projectionImage); }