public static void ComposeOntoBackgroundAcceptanceTest(string fileName)
        {
            Bitmap sourceImage = Program.LoadImage(Program.LoadImageType.Test, fileName);

            Bitmap actualImage = ImageTransforms.ComposeImageOntoPhoto(sourceImage);

            Program.SaveTestImage(actualImage, "actual/" + fileName);

            Bitmap expectedImage = Program.LoadImage(Program.LoadImageType.Test, "expected/" + fileName);

            TestUtils.AssertImagesAreTheSame(expectedImage, actualImage);
        }
Exemple #2
0
        public static Bitmap ComposeImage(Bitmap sourceImage, string descriptionText, float confidence, bool isOld, bool isBlackAndWhitePhoto, float expensiveMultiplier, bool isPainting, bool isSign, int?extractedYear, string extractedLocale, Random random)
        {
            Bitmap drawnBitmap = null;

            if (isPainting || isSign)
            {
                drawnBitmap = ImageTransforms.ComposeImageOntoPhoto(sourceImage);
            }
            else
            {
                drawnBitmap = sourceImage.Clone();
            }

            PriceRange priceRange = GetPriceRange(descriptionText, confidence, expensiveMultiplier, random);
            int        year       = GetYear(drawnBitmap, isOld, isBlackAndWhitePhoto, extractedYear);

            string localePhrase = (extractedLocale != null ? (", " + extractedLocale) : "");

            string fullCaption = descriptionText + String.Format(" (ca. {0}{1})\n ${2}-${3}", year, localePhrase, PriceRange.FormatPrice(priceRange.lowPrice), PriceRange.FormatPrice(priceRange.highPrice));

            Bitmap footerImage = LoadImage(LoadImageType.Source, "footer.png");

            float scale         = (float)drawnBitmap.Width / (float)footerImage.Width;
            float footerHeight  = scale * footerImage.Height;
            float footerOriginY = drawnBitmap.Height - footerHeight;

            float textOriginY = footerOriginY + 10.0f * scale;
            float textOriginX = 200.0f * scale;

            int fontSize = (int)(33 * scale);

            FontFamily family = GetCaptionFontFamily();

            Font font = new Font(family, fontSize, FontStyle.Bold);

            TextGraphicsOptions textGraphicsOptions = new TextGraphicsOptions();

            textGraphicsOptions.TextOptions.WrapTextWidth = drawnBitmap.Width - textOriginX - 10;

            AffineTransformBuilder footerTransformBuilder = new AffineTransformBuilder()
                                                            .AppendScale(new SizeF(scale, scale));

            footerImage.Mutate(x => x.Transform(footerTransformBuilder));

            drawnBitmap.Mutate(x => x.DrawImage(footerImage, new SixLabors.ImageSharp.Point(0, (int)footerOriginY), new GraphicsOptions())
                               .DrawText(textGraphicsOptions, fullCaption, font, NamedColors.White, new PointF(textOriginX + 1, textOriginY + 1)));

            return(drawnBitmap);
        }