Example #1
0
        private static async Task <Image> MergeImagesInternalAsync(List <string> imageUrls, MergeLayoutEnum mergeLayout, Size size)
        {
            int picCount     = 0;
            var stringLayout = mergeLayout.ToString();

            if (stringLayout.StartsWith("Merge1C"))
            {
                picCount = 1;
            }
            else if (stringLayout.StartsWith("Merge2"))
            {
                picCount = 2;
            }
            else if (stringLayout.StartsWith("Merge3"))
            {
                picCount = 3;
            }
            else if (stringLayout.StartsWith("Merge4"))
            {
                picCount = 4;
            }
            else if (stringLayout.StartsWith("Merge8"))
            {
                picCount = 8;
            }

            if (imageUrls.Count < picCount)
            {
                throw new ArgumentException("argument invalid.");
            }

            List <Image> list = new List <Image>(picCount);

            for (int i = 0; i < picCount; i++)
            {
                var bytes = await GetImageByteArrayAsync(imageUrls[i]);

                if (bytes != null && bytes.Length > 0)
                {
                    list.Add(ConvertToImage(bytes));
                }
            }

            var result = MergeImages(list, size, mergeLayout);

            return(result);
        }
Example #2
0
        private static async Task TestMerge(string type, List <string> imagePath, MergeLayoutEnum layout, Size size)
        {
            var m1 = await ImageMergeHelper.MergeImagesAsync(imagePath, layout, size);

            var m1Path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, type + "-" + layout.ToString() + ".png");

            if (File.Exists(m1Path))
            {
                File.Delete(m1Path);
            }
            m1.Save(m1Path);
        }