コード例 #1
0
        public void UnionGroupsImageParams(Group group, List <PngUtil.MergeImageParams> ps)
        {
            if (!GroupLayerCache.ContainsKey(group.Sceneid))
            {
                GroupLayerCache[group.Sceneid] = new SortedDictionary <int, GroupCache>();
            }

            if (ps == null)
            {
                GroupLayerCache[group.Sceneid].Remove(group.LayerIndex);
            }
            else
            {
                GroupLayerCache[group.Sceneid][group.LayerIndex] = new GroupCache
                {
                    GroupLayerId          = group.LayerIndex,
                    GroupSize             = group.Size,
                    GroupPropertiesImages = ps,
                };
            }

            if (GroupLayerCache[group.Sceneid].Count == 0)
            {
                UpdateCenterBoard(group.Sceneid, null);
            }
            else
            {
                List <PngUtil.MergeImageParams> resultList = null;
                GroupSize maxGroupSize = null;
                foreach (GroupCache groupCache in GroupLayerCache[group.Sceneid].Values)
                {
                    if (maxGroupSize == null || groupCache.GroupSize.Width > maxGroupSize.Width)
                    {
                        maxGroupSize = groupCache.GroupSize;
                    }
                    if (resultList == null)
                    {
                        resultList = groupCache.GroupPropertiesImages;
                    }
                    else
                    {
                        resultList = resultList.Union(groupCache.GroupPropertiesImages).ToList();
                    }
                }
                UpdateCenterBoard(group.Sceneid, PngUtil.MergeImageList(resultList, maxGroupSize.Width, maxGroupSize.Height));
            }
        }
コード例 #2
0
        public string StartOutput(Outputs outputs, Dictionary <int, Property> propertyIdMapping, string basePath, Form_Progress progressForm)
        {
            progressForm.SetProgressMax(outputs.ImageOutputs.Length + outputs.XmlOutputs.Length + outputs.MergeImageOutputs.Length);

            foreach (ImageOutput imageOutout in outputs.ImageOutputs)
            {
                if (!propertyIdMapping.ContainsKey(imageOutout.PropertyId))
                {
                    return(Errors.PropertyIdNotExist);
                }

                Property property = propertyIdMapping[imageOutout.PropertyId];

                Control[] controls = GetSceneFlowLayoutPanel(property.SceneId).Controls.Find(property.GetPictureBoxId(), true);
                if (controls == null || controls.Length == 0)
                {
                    return(Errors.UiPictureBoxNotExist);
                }

                try
                {
                    string newFile = Path.Combine(basePath, imageOutout.Target);
                    string dirName = newFile.Substring(0, newFile.LastIndexOf('\\'));

                    if (!Directory.Exists(dirName))
                    {
                        Directory.CreateDirectory(dirName);
                    }

                    ((PictureBox)(controls[0])).Image.Save(newFile);
                }
                catch (Exception ex)
                {
                    return(ex.ToString());
                }
                progressForm.AddProgressValue(1, string.Format("组件:{0},   属性: {1} 导出完毕", property.GroupName, property.Name));
            }

            foreach (XmlOutput xmlOutout in outputs.XmlOutputs)
            {
                if (!propertyIdMapping.ContainsKey(xmlOutout.PropertyId))
                {
                    return(Errors.PropertyIdNotExist);
                }
                Property property = propertyIdMapping[xmlOutout.PropertyId];


                Control[] controls = null;
                if (property.OptType == PropertyOperateType.AlphaWhiteImageSetAlpha)
                {
                    controls = GetSceneFlowLayoutPanel(property.SceneId).Controls.Find(property.GetTextBoxAlphaID(), true);
                }
                else if (property.OptType == PropertyOperateType.AlphaWhiteImageSetColor)
                {
                    controls = GetSceneFlowLayoutPanel(property.SceneId).Controls.Find(property.GetTextBoxColorID(), true);
                }

                if (controls == null || controls.Length == 0)
                {
                    return(Errors.UiPictureBoxNotExist);
                }
                progressForm.AddProgressValue(1, string.Format("组件:{0}, 属性: {1} 导出完毕", property.GroupName, property.Name));
            }


            List <PngUtil.MergeImageParams> list = new List <PngUtil.MergeImageParams>();

            foreach (MergeImageOutput MergeImageOutPut in outputs.MergeImageOutputs)
            {
                Dictionary <int, Property> map = MergeImageOutPut.GetPropertyMap();
                foreach (int proertyId in map.Keys)
                {
                    if (!propertyIdMapping.ContainsKey(proertyId))
                    {
                        return(Errors.PropertyIdNotExist);
                    }

                    Property propertItem = propertyIdMapping[proertyId];
                    if (map.ContainsKey(propertItem.RefPropertyId))   //如果出现引用形式, 则此图不需要参与合成
                    {
                        continue;
                    }

                    Control[] controls = GetSceneFlowLayoutPanel(propertItem.SceneId).Controls.Find(propertItem.GetPictureBoxId(), true);
                    if (controls == null || controls.Length == 0)
                    {
                        return(Errors.UiPictureBoxNotExist);
                    }


                    list.Add(new PngUtil.MergeImageParams
                    {
                        Image = ((PictureBox)(controls[0])).Image,
                    });
                }
                ;

                Image image = null;
                if (list.Count == 1)
                {
                    image = list[0].Image;
                }
                else
                {
                    image = PngUtil.MergeImageList(list, list[0].Image.Width, list[0].Image.Height);
                }

                try
                {
                    string newFile = Path.Combine(basePath, MergeImageOutPut.Target);
                    string dirName = newFile.Substring(0, newFile.LastIndexOf('\\'));

                    if (!Directory.Exists(dirName))
                    {
                        Directory.CreateDirectory(dirName);
                    }

                    image.Save(newFile);
                }
                catch (Exception ex)
                {
                    return(ex.ToString());
                }

                list.Clear();
                progressForm.AddProgressValue(1, string.Format("图片合成导出完毕"));
            }

            return(null);
        }