Ejemplo n.º 1
0
 //private const int ImageValueOnX = 4; //Число фоток в высоту (по оси Y)
 public Image GetImageForPrint(PhotoContainer container)
 {
     switch (container.PhotoMode)
     {
         case PhotoShotMode.Strips4Foto:
             return GetDisplayImageForStrips4Foto(container);
         case PhotoShotMode.Strips3Foto:
             return GetDisplayImageForStrips3Foto(container);
         case PhotoShotMode.Single4Foto1Big:
             return GetDisplayImageSingleWithOneBigPhoto(container);
         case PhotoShotMode.Single4Foto:
             return GetDisplayImageSinglePhoto(container);
         case PhotoShotMode.SingleFoto:
             return GetDisplayImageSingleBigPhoto(container);
         default:
             throw new Exception("Новый неизвестный тип стиля фотографии, функция-адресат для выполнения стиля фото не определен");
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Отправить фотки на создание развертки в рамках контекста
        /// </summary>
        /// <param name="imageList"></param>
        /// <returns></returns>
        private Image GetDisplayImage(List<Image> imageList)
        {
            var imageService = _serviceProvider.GetService<ImageEditorService>();
            var settingsEntity = _serviceProvider.GetService<SettingsService>().GetSettings();

            var photosDescriber = new PhotoContainer()
            {
                PhotoMode = _photoMode,
                Photos = imageList,
                PhotoWidthForScale = 480,
                PhotoHeightForScale = 320,
                LogoImage = settingsEntity.PhotoLogo,
                BackColor = settingsEntity.BackgroundPhotoColor,
                Background = settingsEntity.PhotoBackground
            };

            return imageService.GetImageForPrint(photosDescriber);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// ПОлучить развертку для печати на сплошной фотке, где есть одно фото большое и еще 3 маленьких
        /// </summary>
        /// <param name="imageList"></param>
        /// <param name="imageWidth"></param>
        /// <param name="imageHeight"></param>
        /// <returns></returns>
        private Image GetDisplayImageSingleWithOneBigPhoto(PhotoContainer container)
        {
            if (container.PhotosValue < 4)
                throw new Exception("Для данного типа развертки необзодимо 4 фото в коллекции, сейчас в коллекции " + container.PhotosValue + " фото");

            List<Image> imageList = container.Photos;
            int imageWidth = container.PhotoWidthForScale;
            int newImageWidth = (int)(imageWidth*0.9);
            int imageHeight = container.PhotoHeightForScale;
            var imgLogo = (Image)container.LogoImage.Clone();

            const int offsetBetweenX = 20;
            const int offsetBetweenY = 20;
            const int offsetLeft = 50;//отступ слева
            const int offsetRight = 25;//отступ справа
            const int offsetUp = 25;
            const int offsetBottom = 15;
            const int imageValueOnX = 3;//Количество фоток на одну полоску
            const float multiplier = 2.2f;//Коэффициент отличия размеров маленьких фоток от большой

            int width = offsetLeft + (int)(imageWidth * multiplier) + offsetBetweenX + newImageWidth + offsetRight;
            int height = offsetUp + imageHeight * imageValueOnX + offsetBetweenY * imageValueOnX + offsetBottom;

            Image dest = new Bitmap(width, height, PixelFormat.Format32bppPArgb);

            int x = 0;
            int y = 0;

            using (Graphics gr = Graphics.FromImage(dest))
            {
                if (container.Background != null)
                    gr.DrawImage(container.Background, 0, 0, container.Background.Width, container.Background.Height);
                else
                    gr.FillRectangle(new SolidBrush(container.BackColor), 0, 0, width, height); // Очищаем экран

                gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

                //Сначала прилепим большую картинку
                var image = ScaleImage(imageList[0], (int)(imageWidth * multiplier), (int)(imageHeight * multiplier));
                gr.DrawImage(image, offsetLeft, offsetUp);

                for (int i = 1; i < imageList.Count; i++)
                {
                    x = offsetLeft + (int)(imageWidth * multiplier) + offsetBetweenX;
                    y = offsetUp + offsetBetweenY * (i - 1) + imageHeight * (i - 1);

                    var img = CutOffImage(ScaleImage(imageList[i], imageWidth, imageHeight), newImageWidth, imageHeight);

                    gr.DrawImage(img, x, y);
                }

                int deltaY = height - (offsetUp + (int)(imageHeight * multiplier)) - 20;
                int deltaX = (int)(imageWidth * multiplier);
                int offsetUpAndDown = (int)(deltaY * 0.08);//Что бы снизу и сверху были отсупы, на них отведем 8% доступного пространства

                //Сначала промасштабируем логотип, если логотип больше чем нужно
                var coifecient = ScaleImageForFreespacesSizes(imgLogo, deltaX, deltaY - offsetUpAndDown);

                var point = GetLeftUpPointForDrawScreenOnCenter(deltaX, deltaY - offsetUpAndDown, (int)(imgLogo.Width * coifecient),
                                                                (int)(imgLogo.Height * coifecient));

                //Пересчитать координаты точки из пространства "свободного прямоугольника" в пространство фотографии
                point.Y = point.Y + (offsetUp + (int)(imageHeight * multiplier)) + offsetUpAndDown / 2;
                point.X = point.X + offsetLeft;

                gr.DrawImage(imgLogo, point.X, point.Y+10, imgLogo.Width * coifecient, imgLogo.Height * coifecient);
            }

            dest.RotateFlip(RotateFlipType.Rotate90FlipNone);

            return dest;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// ПОлучить развертку для печати на сплошной фотке, где 4 равных фото
        /// </summary>
        /// <param name="container"></param>
        /// <returns></returns>
        private Image GetDisplayImageSinglePhoto(PhotoContainer container)
        {
            if (container.PhotosValue < 4)
                throw new Exception("Для данного типа развертки необзодимо 4 фото в коллекции, сейчас в коллекции " + container.PhotosValue + " фото");

            List<Image> imageList = container.Photos;
            int imageWidth = container.PhotoWidthForScale;
            int imageHeight = container.PhotoHeightForScale;

            const int offsetBetweenX = 20;
            const int offsetBetweenY = 20;
            const int offsetLeft = 37;//отступ слева
            const int offsetRight = 23;//отступ справа
            const int offsetUp = 40;
            const int offsetBottom = 220;
            const int newImageWidth = 251;//Размер по горизонтали, до которого будем обрезатиь картинку, когда она примет размер imageWidth и imageHeight
            const float multiplier = 1.5f;//Коэффициент масштабирования к указанному размеру
            var imgLogo = (Image)container.LogoImage.Clone();

            int width = offsetLeft + (int)(newImageWidth * multiplier * 2) + offsetBetweenX + offsetRight;
            int height = offsetUp + (int)(imageHeight * multiplier * 2) + offsetBetweenY + offsetBottom;

            Image dest = new Bitmap(width, height, PixelFormat.Format32bppPArgb);

            int x = 0;
            int y = 0;

            using (Graphics gr = Graphics.FromImage(dest))
            {
                if (container.Background != null)
                    gr.DrawImage(container.Background, 0, 0, container.Background.Width, container.Background.Height);
                else
                    gr.FillRectangle(new SolidBrush(container.BackColor), 0, 0, width, height); // Очищаем экран нужным цветом

                gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

                for (int i = 0; i < imageList.Count; i++)
                {
                    x = offsetLeft;
                    //Если число четное - указать игрек
                    //Для высчитывания X - мы всегда делим i на 2 и откидываем остаток

                    if (!IfNumberEven(i))
                        x = offsetLeft + (int)(newImageWidth * multiplier) + offsetBetweenX;

                    var image = CutOffImage(ScaleImage(imageList[i], (int)(imageWidth * multiplier), (int)(imageHeight * multiplier)), (int)(newImageWidth * multiplier), (int)(imageHeight * multiplier));

                    y = (i / 2) * (int)(imageHeight * multiplier) + (i / 2) * offsetBetweenY + offsetUp;

                    gr.DrawImage(image, x, y);
                }

                int deltaY = height - (y + (int)(imageHeight * multiplier));
                int deltaX = width;
                int offsetUpAndDown = (int) (deltaY*0.08);//Что бы снизу и сверху были отсупы, на них отведем 8% доступного пространства

                //Сначала промасштабируем логотип, если логотип больше чем нужно
                var coifecient = ScaleImageForFreespacesSizes(imgLogo, deltaX, deltaY - offsetUpAndDown);

                var point = GetLeftUpPointForDrawScreenOnCenter(deltaX, deltaY - offsetUpAndDown, (int)(imgLogo.Width * coifecient),
                                                                (int)(imgLogo.Height * coifecient));

                //Пересчитать координаты точки из пространства "свободного прямоугольника" в пространство фотографии
                point.Y = point.Y + (y + (int)(imageHeight * multiplier)) + offsetUpAndDown/2 + 5;

                gr.DrawImage(imgLogo, point.X, point.Y, imgLogo.Width * coifecient, imgLogo.Height * coifecient);
            }

            return dest;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Одно большое фото на весь лист
        /// </summary>
        /// <param name="container"></param>
        /// <returns></returns>
        private Image GetDisplayImageSingleBigPhoto(PhotoContainer container)
        {
            int width = 1279;
            int height = 853;
            List<Image> imageList = container.Photos;

            Image dest = new Bitmap(width, height, PixelFormat.Format32bppPArgb);

            using (Graphics gr = Graphics.FromImage(dest))
            {
                gr.FillRectangle(new SolidBrush(container.BackColor), 0, 0, width, height); // Очищаем экран
                gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

                //Сначала прилепим большую картинку
                var image = ScaleImage(imageList[0], (int)width, (int)height);
                gr.DrawImage(image, 0, 0);
            }

            dest.RotateFlip(RotateFlipType.Rotate90FlipNone);

            return dest;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// ПОлучить развертку для печати на 2 полоски по 4 фотки на каждой
        /// </summary>
        /// <param name="container"></param>
        private Image GetDisplayImageForStrips4Foto(PhotoContainer container)
        {
            if(container.PhotosValue < 8)
                throw new Exception("Для данного типа развертки необзодимо 8 фото в коллекции, сейчас в коллекции " + container.PhotosValue + " фото");

            const int offsetBetweenX = 40;
            const int offsetBetweenY = 20;
            const int offsetLeft = 37;//отступ слева
            const int offsetRight = 23;//отступ справа
            const int offsetUp = 50;
            const int offsetBottom = 190;
            const int imageValueOnX = 4;//Количество фоток на одну полоску
            var imgLogo = (Image)container.LogoImage.Clone();

            List<Image> imageList = container.Photos;
            int imageWidth = container.PhotoWidthForScale;
            int imageHeight = container.PhotoHeightForScale;

            int width = offsetLeft + imageWidth * 2 + offsetBetweenX + offsetRight;
            int height = offsetUp + imageHeight * imageValueOnX + offsetBetweenY * (imageValueOnX - 1) + offsetBottom;

            Image dest = new Bitmap(width, height, PixelFormat.Format32bppPArgb);

            int x = 0;
            int y = 0;

            using (Graphics gr = Graphics.FromImage(dest))
            {
                if (container.Background != null)
                    gr.DrawImage(container.Background, 0, 0, container.Background.Width, container.Background.Height);
                else
                    gr.FillRectangle(new SolidBrush(container.BackColor), 0, 0, width, height); // Очищаем экран нужным цветом

                gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

                for (int i = 0; i < imageList.Count; i++)
                {
                    x = offsetLeft;
                    //Если число четное - указать игрек
                    //Для высчитывания X - мы всегда делим i на 2 и откидываем остаток

                    if (!IfNumberEven(i))
                        x = offsetLeft + imageWidth + offsetBetweenX;

                    var image = ScaleImage(imageList[i], imageWidth, imageHeight);

                    y = (i / 2) * imageHeight + (i / 2) * offsetBetweenY + offsetUp;

                    gr.DrawImage(image, x, y);
                }

                int deltaY = height - (y + (int)(imageHeight));
                int deltaX = imageWidth + offsetLeft;
                int offsetUpAndDown = (int)(deltaY * 0.08);//Что бы снизу и сверху были отсупы, на них отведем 8% доступного пространства

                //Сначала промасштабируем логотип, если логотип больше чем нужно
                var coifecient = ScaleImageForFreespacesSizes(imgLogo, deltaX, deltaY - offsetUpAndDown);

                var point = GetLeftUpPointForDrawScreenOnCenter(deltaX, deltaY - offsetUpAndDown, (int)(imgLogo.Width * coifecient),
                                                                (int)(imgLogo.Height * coifecient));

                //Пересчитать координаты точки из пространства "свободного прямоугольника" в пространство фотографии
                point.Y = point.Y + (y + (int)(imageHeight)) + offsetUpAndDown / 2 + 2;

                gr.DrawImage(imgLogo, point.X, point.Y, imgLogo.Width * coifecient, imgLogo.Height * coifecient);

                //нарисовать логотип под 2-м фото
                point.X += imageWidth + offsetBetweenX;
                gr.DrawImage(imgLogo, point.X, point.Y, imgLogo.Width * coifecient, imgLogo.Height * coifecient);
            }
            return dest;
        }