/// <summary>
        /// Generates the title image for the mission.
        /// </summary>
        /// <param name="missionName">The name of the mission.</param>
        /// <returns>The mission title image, as an array of bytes for a JPEG file.</returns>
        private byte[] GetTitleImage(string missionName)
        {
            byte[]    imageBytes;
            Rectangle rect;
            int       x, y;

            using (Image titleImage = GetImageIfItExists("Jpg\\Title.jpg"))
            {
                using (Graphics g = Graphics.FromImage(titleImage))
                {
                    using (Font font = new Font("Arial", 48, FontStyle.Regular, GraphicsUnit.Point))
                    {
                        for (x = -1; x <= 1; x++)
                        {
                            for (y = -1; y <= 1; y++)
                            {
                                if ((x == 0) && (y == 0))
                                {
                                    continue;
                                }
                                rect = new Rectangle(x * 1, y * 1, 512, 512);
                                TextRenderer.DrawText(g, missionName, font, rect, Color.Black, HQTools.CENTER_TEXT_FLAGS);
                            }
                        }

                        rect = new Rectangle(0, 0, 512, 512);
                        TextRenderer.DrawText(g, missionName, font, rect, Color.White, HQTools.CENTER_TEXT_FLAGS);
                    }
                }

                imageBytes = HQTools.ImageToBytes(titleImage, ImageFormat.Jpeg);
            }

            return(imageBytes);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates all custom kneeboard images and returns them as a dictionary of byte arrays.
        /// </summary>
        /// <param name="mission">An HQ4DCS mission.</param>
        /// <returns>A dictionary of entries to include the .miz file. Key is the entry name, value is an array holding the bytes of the entry.</returns>
        public Dictionary <string, byte[]> MakeKneeboardImages(DCSMission mission)
        {
            Dictionary <string, byte[]> kneeboardImages = new Dictionary <string, byte[]>();

            DebugLog.Instance.Log($"Adding kneeboard images...");

            Image kneeboardImage = null;

            using (HTMLExporter htmlExporter = new HTMLExporter())
            { kneeboardImage = htmlExporter.ExportToImage(mission.BriefingHTML); }
            if (kneeboardImage == null)
            {
                return(kneeboardImages);                        // Failed to generate an image, abort
            }
            // TODO: format is wrong - should be 768x1024
            // TODO: briefing should be split in multiple pages to make sure even long briefings are readable
            foreach (string acType in mission.UsedPlayerAircraftTypes)
            {
                kneeboardImages.Add($"KNEEBOARD/{acType}/IMAGES/01.png", HQTools.ImageToBytes(kneeboardImage, ImageFormat.Png));
            }

            return(kneeboardImages);
        }