Esempio n. 1
0
        private static ImageElement GenerateImageElement(Image image, Rectangle destRectangle, OffsetXType offsetX, OffsetYType offsetY)
        {
            (var zoomImage, var dest) = ZoomImage(image, destRectangle.Height, destRectangle.Width, true);
            Rectangle srcRectangle = new Rectangle(0, 0, zoomImage.Width, zoomImage.Height);
            var       imageElement = new ImageElement {
                Image = zoomImage, DestRectangle = destRectangle, SrcRectangle = srcRectangle
            };

            switch (offsetX)
            {
            case OffsetXType.PositiveX:
                imageElement.OffsetX = dest.X;
                break;

            case OffsetXType.NegativeX:
                imageElement.OffsetX = -dest.X;
                break;

            case OffsetXType.NoOffsetX:
                imageElement.OffsetX = 0;
                break;
            }

            switch (offsetY)
            {
            case OffsetYType.PositiveY:
                imageElement.OffsetY = dest.Y;
                break;

            case OffsetYType.NegativeY:
                imageElement.OffsetY = -dest.Y;
                break;

            case OffsetYType.NoOffsetY:
                imageElement.OffsetY = 0;
                break;
            }

            return(imageElement);
        }
Esempio n. 2
0
        private static List <ImageElement> GetImageElements(List <Image> images, Size size, MergeLayoutEnum mergeLayout)
        {
            List <ImageElement> list = new List <ImageElement>();
            var height    = size.Height;
            var width     = size.Width;
            int newHeight = 0;
            int newWidth  = 0;

            switch (mergeLayout)
            {
            case MergeLayoutEnum.Merge1C:
                for (int i = 0; i < images.Count; i++)
                {
                    Rectangle destRectangle = new Rectangle(0, 0, width, height);
                    var       imageElement  = GenerateImageElement(images[i], destRectangle, OffsetXType.NoOffsetX, OffsetYType.NoOffsetY);
                    list.Add(imageElement);
                }

                break;

            case MergeLayoutEnum.Merge2TB:
                for (int i = 0; i < images.Count; i++)
                {
                    newHeight = height / 2;        // =125
                    newWidth  = width;             //  =250
                    (var zoomImage, var dest) = ZoomImage(images[i], newHeight, newWidth, true);
                    var element = new ImageElement {
                        Image = zoomImage, SrcRectangle = new Rectangle(0, 0, zoomImage.Width, zoomImage.Height)
                    };
                    element.DestRectangle = new Rectangle(0, 0, newWidth, newHeight);
                    if (i == 0)
                    {
                        element.OffsetY = dest.Y;
                    }
                    else if (i == 1)
                    {
                        element.DestRectangle = new Rectangle(0, size.Height / 2, newWidth, newHeight);
                        element.OffsetY       = -dest.Y;
                    }
                    list.Add(element);
                }

                break;

            case MergeLayoutEnum.Merge2LR:
                for (int i = 0; i < images.Count; i++)
                {
                    newWidth  = width / 2;   //   =125
                    newHeight = height;      //   =250
                    (var zoomImage, var dest) = ZoomImage(images[i], newHeight, newWidth, true);
                    var element = new ImageElement {
                        Image = zoomImage, SrcRectangle = new Rectangle(0, 0, zoomImage.Width, zoomImage.Height)
                    };
                    element.DestRectangle = new Rectangle(0, 0, newWidth, newHeight);
                    if (i == 0)
                    {
                        element.OffsetX = dest.X;
                    }
                    if (i == 1)
                    {
                        element.DestRectangle = new Rectangle(size.Width / 2, 0, newWidth, newHeight);
                        element.OffsetX       = -dest.X;
                    }
                    list.Add(element);
                }

                break;

            case MergeLayoutEnum.Merge3T1B2:
                for (int i = 0; i < images.Count; i++)
                {
                    Rectangle   destRectangle;
                    OffsetXType offsetX = OffsetXType.NoOffsetX;
                    OffsetYType offsetY = OffsetYType.NoOffsetY;

                    if (i == 0)
                    {
                        newHeight     = height / 2; // =125
                        newWidth      = width;      //       =250
                        destRectangle = new Rectangle(0, 0, newWidth, newHeight);
                        offsetY       = OffsetYType.PositiveY;
                    }
                    else if (i == 1)
                    {
                        newHeight     = height / 2; //  =125
                        newWidth      = width / 2;  //  =125
                        destRectangle = new Rectangle(0, height / 2, newWidth, newHeight);
                        offsetX       = OffsetXType.PositiveX;
                        offsetY       = OffsetYType.NegativeY;
                    }
                    else
                    {
                        newHeight     = height / 2; //  =125
                        newWidth      = width / 2;  //  =125
                        destRectangle = new Rectangle(width / 2, height / 2, newWidth, newHeight);
                        offsetY       = OffsetYType.NegativeY;
                        offsetX       = OffsetXType.NegativeX;
                    }

                    var imageElement = GenerateImageElement(images[i], destRectangle, offsetX, offsetY);
                    list.Add(imageElement);
                }
                break;

            case MergeLayoutEnum.Merge3T2B1:
                for (int i = 0; i < images.Count; i++)
                {
                    Rectangle   destRectangle;
                    OffsetXType offsetX = OffsetXType.NoOffsetX;
                    OffsetYType offsetY = OffsetYType.NoOffsetY;
                    if (i == 0)
                    {
                        newHeight     = height / 2; //  =125
                        newWidth      = width / 2;  //  =125
                        destRectangle = new Rectangle(0, 0, newWidth, newHeight);
                        offsetX       = OffsetXType.PositiveX;
                        offsetY       = OffsetYType.PositiveY;
                    }
                    else if (i == 1)
                    {
                        newHeight     = height / 2; //  =125
                        newWidth      = width / 2;  //  =125
                        destRectangle = new Rectangle(width / 2, 0, newWidth, newHeight);
                        offsetY       = OffsetYType.PositiveY;
                        offsetX       = OffsetXType.NegativeX;
                    }
                    else
                    {
                        newHeight     = height / 2; // =125
                        newWidth      = width;      //       =250
                        destRectangle = new Rectangle(0, height / 2, newWidth, newHeight);
                        offsetY       = OffsetYType.NegativeY;
                    }

                    var imageElement = GenerateImageElement(images[i], destRectangle, offsetX, offsetY);
                    list.Add(imageElement);
                }
                break;

            case MergeLayoutEnum.Merge3L1R2:
                for (int i = 0; i < images.Count; i++)
                {
                    Rectangle   destRectangle;
                    OffsetXType offsetX = OffsetXType.NoOffsetX;
                    OffsetYType offsetY = OffsetYType.NoOffsetY;
                    if (i == 0)
                    {
                        newHeight     = height;    //     =250
                        newWidth      = width / 2; //   =125
                        destRectangle = new Rectangle(0, 0, newWidth, newHeight);
                        offsetX       = OffsetXType.PositiveX;
                    }
                    else if (i == 1)
                    {
                        newHeight     = height / 2; //  =125
                        newWidth      = width / 2;  //  =125
                        destRectangle = new Rectangle(width / 2, 0, newWidth, newHeight);
                        offsetX       = OffsetXType.NegativeX;
                        offsetY       = OffsetYType.PositiveY;
                    }
                    else
                    {
                        newHeight     = height / 2; //  =125
                        newWidth      = width / 2;  //  =125
                        destRectangle = new Rectangle(width / 2, height / 2, newWidth, newHeight);
                        offsetX       = OffsetXType.NegativeX;
                        offsetY       = OffsetYType.NegativeY;
                    }

                    var imageElement = GenerateImageElement(images[i], destRectangle, offsetX, offsetY);
                    list.Add(imageElement);
                }
                break;

            case MergeLayoutEnum.Merge3L2R1:
                for (int i = 0; i < images.Count; i++)
                {
                    Rectangle   destRectangle;
                    OffsetXType offsetX = OffsetXType.NoOffsetX;
                    OffsetYType offsetY = OffsetYType.NoOffsetY;
                    if (i == 0)
                    {
                        newHeight     = height / 2; //  =125
                        newWidth      = width / 2;  //  =125
                        destRectangle = new Rectangle(0, 0, newWidth, newHeight);
                        offsetX       = OffsetXType.PositiveX;
                        offsetY       = OffsetYType.PositiveY;
                    }
                    else if (i == 1)
                    {
                        newHeight     = height / 2; //  =125
                        newWidth      = width / 2;  //  =125
                        destRectangle = new Rectangle(0, height / 2, newWidth, newHeight);
                        offsetX       = OffsetXType.PositiveX;
                        offsetY       = OffsetYType.NegativeY;
                    }
                    else
                    {
                        newHeight     = height;    //     =250
                        newWidth      = width / 2; //   =125
                        destRectangle = new Rectangle(width / 2, 0, newWidth, newHeight);
                        offsetX       = OffsetXType.NegativeX;
                    }

                    var imageElement = GenerateImageElement(images[i], destRectangle, offsetX, offsetY);
                    list.Add(imageElement);
                }
                break;

            case MergeLayoutEnum.Merge4S:
                for (int i = 0; i < images.Count; i++)
                {
                    Rectangle destRectangle;
                    newHeight = height / 2;    //  =125
                    newWidth  = width / 2;     //  =125
                    OffsetXType offsetX = OffsetXType.NoOffsetX;
                    OffsetYType offsetY = OffsetYType.NoOffsetY;

                    if (i == 0)
                    {
                        destRectangle = new Rectangle(0, 0, newWidth, newHeight);
                        offsetX       = OffsetXType.PositiveX;
                        offsetY       = OffsetYType.PositiveY;
                    }
                    else if (i == 1)
                    {
                        destRectangle = new Rectangle(width / 2, 0, newWidth, newHeight);
                        offsetX       = OffsetXType.NegativeX;
                        offsetY       = OffsetYType.PositiveY;
                    }
                    else if (i == 2)
                    {
                        destRectangle = new Rectangle(0, height / 2, newWidth, newHeight);
                        offsetX       = OffsetXType.PositiveX;
                        offsetY       = OffsetYType.NegativeY;
                    }
                    else
                    {
                        destRectangle = new Rectangle(width / 2, height / 2, newWidth, newHeight);
                        offsetX       = OffsetXType.NegativeX;
                        offsetY       = OffsetYType.NegativeY;
                    }

                    var imageElement = GenerateImageElement(images[i], destRectangle, offsetX, offsetY);
                    list.Add(imageElement);
                }
                break;

            case MergeLayoutEnum.Merge8T4B4:
                for (int i = 0; i < images.Count; i++)
                {
                    Rectangle destRectangle;
                    newHeight = height / 2;    //  =125
                    newWidth  = width / 4;     //  =125
                    OffsetXType offsetX = OffsetXType.NoOffsetX;
                    OffsetYType offsetY = OffsetYType.NoOffsetY;

                    if (i == 0)
                    {
                        destRectangle = new Rectangle(0, 0, newWidth, newHeight);
                        offsetY       = OffsetYType.PositiveY;
                    }
                    else if (i == 1)
                    {
                        destRectangle = new Rectangle(width / 4, 0, newWidth, newHeight);
                        offsetY       = OffsetYType.PositiveY;
                    }
                    else if (i == 2)
                    {
                        destRectangle = new Rectangle(width / 2, 0, newWidth, newHeight);
                        offsetY       = OffsetYType.PositiveY;
                    }
                    else if (i == 3)
                    {
                        destRectangle = new Rectangle(width / 4 * 3, 0, newWidth, newHeight);
                        offsetY       = OffsetYType.PositiveY;
                    }
                    else if (i == 4)
                    {
                        destRectangle = new Rectangle(0, height / 2, newWidth, newHeight);
                        offsetY       = OffsetYType.NegativeY;
                    }
                    else if (i == 5)
                    {
                        destRectangle = new Rectangle(width / 4, height / 2, newWidth, newHeight);
                        offsetY       = OffsetYType.NegativeY;
                    }
                    else if (i == 6)
                    {
                        destRectangle = new Rectangle(width / 2, height / 2, newWidth, newHeight);
                        offsetY       = OffsetYType.NegativeY;
                    }
                    else
                    {
                        destRectangle = new Rectangle(width / 4 * 3, height / 2, newWidth, newHeight);
                        offsetY       = OffsetYType.NegativeY;
                    }

                    var imageElement = GenerateImageElement(images[i], destRectangle, offsetX, offsetY);
                    list.Add(imageElement);
                }
                break;

            case MergeLayoutEnum.Merge8L4R4:
                for (int i = 0; i < images.Count; i++)
                {
                    Rectangle destRectangle;
                    newHeight = height / 4;    //  =125
                    newWidth  = width / 2;     //  =125
                    OffsetXType offsetX = OffsetXType.NoOffsetX;
                    OffsetYType offsetY = OffsetYType.NoOffsetY;

                    if (i == 0)
                    {
                        destRectangle = new Rectangle(0, 0, newWidth, newHeight);
                        offsetX       = OffsetXType.PositiveX;
                    }
                    else if (i == 1)
                    {
                        destRectangle = new Rectangle(0, height / 4, newWidth, newHeight);
                        offsetX       = OffsetXType.PositiveX;
                    }
                    else if (i == 2)
                    {
                        destRectangle = new Rectangle(0, height / 2, newWidth, newHeight);
                        offsetX       = OffsetXType.PositiveX;
                    }
                    else if (i == 3)
                    {
                        destRectangle = new Rectangle(0, height / 4 * 3, newWidth, newHeight);
                        offsetX       = OffsetXType.PositiveX;
                    }
                    else if (i == 4)
                    {
                        destRectangle = new Rectangle(width / 2, 0, newWidth, newHeight);
                        offsetX       = OffsetXType.NegativeX;
                    }
                    else if (i == 5)
                    {
                        destRectangle = new Rectangle(width / 2, height / 4, newWidth, newHeight);
                        offsetX       = OffsetXType.NegativeX;
                    }
                    else if (i == 6)
                    {
                        destRectangle = new Rectangle(width / 2, height / 2, newWidth, newHeight);
                        offsetX       = OffsetXType.NegativeX;
                    }
                    else
                    {
                        destRectangle = new Rectangle(width / 2, height / 4 * 3, newWidth, newHeight);
                        offsetX       = OffsetXType.NegativeX;
                    }

                    var imageElement = GenerateImageElement(images[i], destRectangle, offsetX, offsetY);
                    list.Add(imageElement);
                }
                break;
            }

            return(list);
        }