Пример #1
0
        private static Image GenerateSkyboxPreview(SRTSkybox skybox, string previewFileName)
        {
            Process vtfcmd = new Process();
            vtfcmd.StartInfo.FileName = vtfcmdPath;
            vtfcmd.StartInfo.Arguments = "-exportformat bmp -file \"" + skybox.GetVTF(0) + "\" -file \"" + skybox.GetVTF(1) + "\" -file \"" + skybox.GetVTF(2) + "\" -file \"" + skybox.GetVTF(3) + "\"";
            vtfcmd.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            vtfcmd.Start();
            vtfcmd.WaitForExit();

            string lfBmp = skybox.FileName + Sides[0] + ".bmp";
            string bkBmp = skybox.FileName + Sides[1] + ".bmp";
            string rtBmp = skybox.FileName + Sides[2] + ".bmp";
            string ftBmp = skybox.FileName + Sides[3] + ".bmp";

            Image lf = Image.FromFile(lfBmp);
            Image bk = Image.FromFile(bkBmp);
            Image rt = Image.FromFile(rtBmp);
            Image ft = Image.FromFile(ftBmp);

            Image previewFull = new Bitmap(lf.Width + bk.Width + rt.Width + ft.Width, Math.Max(Math.Max(lf.Height, bk.Height), Math.Max(rt.Height, ft.Height)));
            Graphics previewFullGraphics = Graphics.FromImage(previewFull);
            previewFullGraphics.DrawImageUnscaled(lf, 0, -1);
            previewFullGraphics.DrawImageUnscaled(bk, lf.Width, -1);
            previewFullGraphics.DrawImageUnscaled(rt, lf.Width + bk.Width, -1);
            previewFullGraphics.DrawImageUnscaled(ft, lf.Width + bk.Width + rt.Width, -1);
            previewFullGraphics.DrawString(skybox.Name, new Font("Segoe UI Semibold", lf.Height / 8, System.Drawing.FontStyle.Bold), Brushes.White, lf.Width / 8, lf.Height - lf.Height / 16, new StringFormat() { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Far });
            previewFullGraphics.Dispose();

            lf.Dispose();
            bk.Dispose();
            rt.Dispose();
            ft.Dispose();

            File.Delete(lfBmp);
            File.Delete(bkBmp);
            File.Delete(rtBmp);
            File.Delete(ftBmp);

            Image preview = new Bitmap(600, 150);
            Graphics previewGraphics = Graphics.FromImage(preview);
            previewGraphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            previewGraphics.DrawImage(previewFull, 0, 0, preview.Width, preview.Height);
            previewGraphics.Dispose();
            previewFull.Dispose();
            preview.Save(previewFileName);

            return preview;
        }