コード例 #1
0
        private void button_UseBlank_Click(object sender, EventArgs e)
        {
            DialogResult result = DarkMessageBox.Show(this, "Are you sure you want to apply a blank image?", "Are you sure?",
                                                      MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
            {
                try
                {
                    Bitmap bitmap = new Bitmap(512, 256);

                    using (Graphics graphics = Graphics.FromImage(bitmap))
                    {
                        Rectangle imageSize = new Rectangle(0, 0, 512, 256);
                        graphics.FillRectangle(Brushes.Black, imageSize);
                    }

                    string pakFilePath  = Path.Combine(_ide.Project.EnginePath, @"data\uklogo.pak");
                    byte[] rawImageData = ImageHandling.GetRawDataFromBitmap(bitmap);

                    PakFile.SavePakFile(pakFilePath, rawImageData);
                    UpdatePreview();
                }
                catch (Exception ex)
                {
                    DarkMessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
コード例 #2
0
        private void button_Change_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog dialog = new OpenFileDialog())
            {
                dialog.Filter = "All Supported Files|*.bmp;*.png|Bitmap Files|*.bmp|PNG Files|*.png";

                if (dialog.ShowDialog(this) == DialogResult.OK)
                {
                    try
                    {
                        using (Image image = Image.FromFile(dialog.FileName))
                        {
                            if (image.Width != 512 || image.Height != 256)
                            {
                                throw new ArgumentException("Wrong image size. The size of the logo has to be 512x256 px.");
                            }

                            string pakFilePath  = Path.Combine(_ide.Project.EnginePath, @"data\uklogo.pak");
                            byte[] rawImageData = null;

                            if (Path.GetExtension(dialog.FileName).ToLower() == ".bmp")
                            {
                                rawImageData = ImageHandling.GetRawDataFromBitmap((Bitmap)image);
                            }
                            else if (Path.GetExtension(dialog.FileName).ToLower() == ".png")
                            {
                                rawImageData = ImageHandling.GetRawDataFromImage(image);
                            }

                            PakFile.SavePakFile(pakFilePath, rawImageData);
                            UpdatePreview();
                        }
                    }
                    catch (Exception ex)
                    {
                        DarkMessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }