/// <see cref="ImageConverter.ConvertSelectedArea(Font, Image, string, bool)"/> public override Image ConvertSelectedArea(Font font, Image img, string subset, bool colorConversion) { ASCIICharHolder holder = GetAppropriateHolder(font, subset); try { int x0 = Math.Min(Form1.rectStartPoint.X, Form1.rectEndPoint.X); int y0 = Math.Min(Form1.rectStartPoint.Y, Form1.rectEndPoint.Y); int width = Math.Abs(Form1.rectStartPoint.X - Form1.rectEndPoint.X); int height = Math.Abs(Form1.rectStartPoint.Y - Form1.rectEndPoint.Y); if (font.Size > width || font.Height > height) { return(img); } Rectangle cloneRect = new Rectangle(x0, y0, width, height); Image convertPartImage = ((Bitmap)img).Clone(cloneRect, img.PixelFormat); ImageGrayScaler imgProcesser = new ImageGrayScaler((Bitmap)convertPartImage); originalImg = (Bitmap)convertPartImage; convertPartImage = imgProcesser.ConvertToGrayScale(); convertPartImage = ConvertToASCII((Bitmap)convertPartImage, font, holder, colorConversion); using (Graphics g = Graphics.FromImage(img)) { g.DrawImage(convertPartImage, cloneRect); } return(img); } catch (Exception) { throw new Exception("Image conversion failed"); } }
/// <see cref="ImageConverter.ConvertFullImage(Font, Image, string, bool)"/> public override Image ConvertFullImage(Font font, Image img, string subset, bool colorConversion) { ImageGrayScaler imgProcesser = new ImageGrayScaler((Bitmap)img); originalImg = (Bitmap)img; img = imgProcesser.ConvertToGrayScale(); ASCIICharHolder holder = GetAppropriateHolder(font, subset); try { return(ConvertToASCII((Bitmap)img, font, holder, colorConversion)); } catch (Exception) { throw new Exception("Image conversion failed"); } }