示例#1
0
    public static CGearBackground GetCGearBackground(Bitmap img)
    {
        const int Width  = CGearBackground.Width;
        const int Height = CGearBackground.Height;

        if (img.Width != Width)
        {
            throw new ArgumentException($"Invalid image width. Expected {Width} pixels wide.");
        }
        if (img.Height != Height)
        {
            throw new ArgumentException($"Invalid image height. Expected {Height} pixels high.");
        }
        if (img.PixelFormat is not PixelFormat.Format32bppArgb)
        {
            throw new ArgumentException($"Invalid image format. Expected {PixelFormat.Format32bppArgb}");
        }

        // get raw bytes of image
        byte[]    data = ImageUtil.GetPixelData(img);
        const int bpp  = 4;

        Debug.Assert(data.Length == Width * Height * bpp);

        return(CGearBackground.GetBackground(data, bpp));
    }
示例#2
0
    private void B_ImportCGB_Click(object sender, EventArgs e)
    {
        using var ofd = new OpenFileDialog
              {
                  Filter = CGearBackground.Filter + "|PokeStock C-Gear Skin|*.psk",
              };

        if (ofd.ShowDialog() != DialogResult.OK)
        {
            return;
        }

        var path = ofd.FileName;
        var len  = new FileInfo(path).Length;

        if (len != CGearBackground.SIZE_CGB)
        {
            WinFormsUtil.Error($"Incorrect size, got {len} bytes, expected {CGearBackground.SIZE_CGB} bytes.");
            return;
        }

        byte[] data = File.ReadAllBytes(path);
        bg = new CGearBackground(data);
        PB_Background.Image = CGearImage.GetBitmap(bg);
    }
示例#3
0
    private void B_ImportPNG_Click(object sender, EventArgs e)
    {
        using var ofd = new OpenFileDialog
              {
                  Filter   = "PNG File|*.png",
                  FileName = "Background.png",
              };

        if (ofd.ShowDialog() != DialogResult.OK)
        {
            return;
        }

        Bitmap img = (Bitmap)Image.FromFile(ofd.FileName);

        try
        {
            bg = CGearImage.GetCGearBackground(img);
            PB_Background.Image = CGearImage.GetBitmap(bg);
        }
        catch (Exception ex)
        {
            WinFormsUtil.Error(ex.Message);
        }
    }
示例#4
0
    public SAV_CGearSkin(SaveFile sav)
    {
        InitializeComponent();
        WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
        SAV = (SAV5)(Origin = sav).Clone();

        byte[] data = SAV.CGearSkinData;
        bg = new CGearBackground(data);

        PB_Background.Image = CGearImage.GetBitmap(bg);
    }
示例#5
0
        public SAV_CGearSkin()
        {
            InitializeComponent();

            SAV = (SAV5)Main.SAV.Clone();

            bool cgearPresent = SAV.Data[SAV.CGearInfoOffset + 0x26] == 1;
            bg = new CGearBackground(cgearPresent ?
                CGearBackground.PSKtoCGB(SAV.Data.Skip(SAV.CGearDataOffset).Take(CGearBackground.SIZE_CGB).ToArray(), SAV.B2W2)
                : new byte[CGearBackground.SIZE_CGB]);

            PB_Background.Image = bg.GetImage();
        }
示例#6
0
        private void B_ImportCGB_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog
            {
                Filter = CGearBackground.Filter + "|PokeStock C-Gear Skin|*.psk"
            };

            if (ofd.ShowDialog() != DialogResult.OK)
                return;

            var len = new FileInfo(ofd.FileName).Length;
            if (len != CGearBackground.SIZE_CGB)
            {
                Util.Error($"Incorrect size, got {len} bytes, expected {CGearBackground.SIZE_CGB} bytes.");
                return;
            }

            byte[] data = File.ReadAllBytes(ofd.FileName);
            if (!CGearBackground.getIsCGB(data))
            {
                bool B2W2 = data[0x2000] != 0x00;
                data = CGearBackground.PSKtoCGB(data, B2W2);
            }

            bg = new CGearBackground(data);
            PB_Background.Image = bg.GetImage();
        }
示例#7
0
 public static Bitmap GetBitmap(CGearBackground bg)
 {
     return(ImageUtil.GetBitmap(bg.GetImageData(), CGearBackground.Width, CGearBackground.Height));
 }