Пример #1
0
        public void SaveAtlas(string path, SaveType atlasType, IEnumerable <RenderTask> renderTasks)
        {
            List <SubTextureStruct> ImageList  = new List <SubTextureStruct>();
            SubTextureStruct        SubTexture = new SubTextureStruct();

            foreach (var render in renderTasks)
            {
                SubTexture.FName = render.TankId;
                using (MemoryStream outStream = new MemoryStream())
                {
                    PngBitmapEncoder encoder = new PngBitmapEncoder();
                    encoder.Frames.Add(BitmapFrame.Create(render.Image));
                    encoder.Save(outStream);
                    SubTexture.ImageTank = new System.Drawing.Bitmap(outStream);
                }
                SubTexture.LocRect = new System.Drawing.Rectangle(0, 0, render.Image.PixelWidth,
                                                                  render.Image.PixelHeight);
                if (atlasType != SaveType.CustomAtlas)
                {
                    SubTexture.MaxParty = Math.Max(render.Image.PixelWidth, render.Image.PixelHeight);
                }
                ImageList.Add(SubTexture);
            }

            if (atlasType != SaveType.CustomAtlas)
            {
                this.CreateImageList(ref ImageList, context, atlasType);
                this.RadixSort(ref ImageList);
            }

            this.Arrangement(ref ImageList);
            Directory.CreateDirectory(Path.GetDirectoryName(path));
            this.CreateAtlasImage(ref ImageList, path);
            this.CreateAtlasXML(ref ImageList, path.Replace(".png", ".xml"));
        }
Пример #2
0
        private void CreateImageList(ref List <SubTextureStruct> ImageList, WotContext context, SaveType atlasType)
        {
            int X, Y, Width, Height, i;
            int BeginCount = ImageList.Count;

            var nameAtlas  = atlasType == SaveType.BattleAtlas ? battleAtlas : vehicleMarkerAtlas;
            var guiPackage = context.VersionConfig.GuiPackageName.Split(' ', ',', ';');

            Stream StreamAtlasDDS = null;

            foreach (string items in guiPackage)
            {
                StreamAtlasDDS = ZipCache.GetZipFileStream(new CompositePath(context, context.Installation.Path, context.VersionConfig.PathSourceAtlas.Replace("\"GuiPackage\"", items), nameAtlas + ".dds"));
                if (StreamAtlasDDS != null)
                {
                    break;
                }
            }

            System.Drawing.Bitmap AtlasPNG = null;
            try
            {
                using (MemoryStream memStream = new MemoryStream())
                {
                    using (MagickImage AtlasDDS = new MagickImage(StreamAtlasDDS))
                    {
                        AtlasDDS.Format = MagickFormat.Png;
                        AtlasDDS.Write(memStream);
                        AtlasPNG = new System.Drawing.Bitmap(memStream);
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Error: " + e.Message, "CreateImageList", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            AtlasPNG.SetResolution(96.0F, 96.0F);

            Stream StreamAtlasXML = null;

            foreach (string items in guiPackage)
            {
                StreamAtlasXML = ZipCache.GetZipFileStream(new CompositePath(context, context.Installation.Path, context.VersionConfig.PathSourceAtlas.Replace("\"GuiPackage\"", items), nameAtlas + ".xml"));
                if (StreamAtlasXML != null)
                {
                    break;
                }
            }
            XDocument AtlasXML = XDocument.Load(StreamAtlasXML);

            XElement         Root           = AtlasXML.Element("root");
            SubTextureStruct SubTextureTemp = new SubTextureStruct();

            foreach (XElement element in Root.Elements())
            {
                SubTextureTemp.FName = element.Element("name").Value.Trim();
                i = 0;
                while ((i < BeginCount) && (SubTextureTemp.FName != ImageList[i].FName))
                {
                    i++;
                }
                if (i >= BeginCount)
                {
                    X      = Convert.ToInt32(element.Element("x").Value.Trim());
                    Y      = Convert.ToInt32(element.Element("y").Value.Trim());
                    Width  = Convert.ToInt32(element.Element("width").Value.Trim());
                    Height = Convert.ToInt32(element.Element("height").Value.Trim());
                    SubTextureTemp.ImageTank = new System.Drawing.Bitmap(Width, Height);
                    SubTextureTemp.ImageTank.SetResolution(96.0F, 96.0F);
                    SubTextureTemp.MaxParty = Math.Max(Width, Height);
                    using (System.Drawing.Graphics gPNG = System.Drawing.Graphics.FromImage(SubTextureTemp.ImageTank))
                    {
                        gPNG.DrawImage(AtlasPNG, 0, 0, new System.Drawing.Rectangle(X, Y, Width, Height), System.Drawing.GraphicsUnit.Pixel);
                    }
                    SubTextureTemp.LocRect = new System.Drawing.Rectangle(0, 0, Width, Height);
                    ImageList.Add(SubTextureTemp);
                }
            }
        }