示例#1
0
        private void InsertFile(string path)
        {
            if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Overwrite image?"))
            {
                return;
            }
            byte[] data = File.ReadAllBytes(path);
            byte[] bclim;

            if (Path.GetExtension(path) == ".bclim") // bclim opened
            {
                var img = BCLIM.Analyze(data, path);
                if (img.Width != PB_Image.Width || img.Height != PB_Image.Height)
                {
                    WinFormsUtil.Alert("Image sizes do not match.",
                                       $"Width: {img.Width} - {PB_Image.Width}\nHeight: {img.Height} - {PB_Image.Height}");
                    return;
                }
                bclim = data;
            }
            else // image
            {
                using Stream BitmapStream = new MemoryStream(data);
                Image img = Image.FromStream(BitmapStream);
                if (img.Width != PB_Image.Width || img.Height != PB_Image.Height)
                {
                    WinFormsUtil.Alert("Image sizes do not match.",
                                       $"Width: {img.Width} - {PB_Image.Width}\nHeight: {img.Height} - {PB_Image.Height}");
                    return;
                }
                bclim = BCLIM.IMGToBCLIM(img, '9');
            }

            string filename = CB_File.Text;
            int    entry    = -1;
            // Find entry in darc
            var darc = darcs[CB_DARC.SelectedIndex];

            for (int i = 0; i < darc.Entries.Length; i++)
            {
                if (darc.FileNameTable[i].FileName == filename)
                {
                    entry = i;
                    break;
                }
            }

            if (entry < 0)
            {
                throw new Exception("File not found!?");
            }

            DARC.InsertFile(ref darc, entry, bclim);
            darcs[CB_DARC.SelectedIndex] = darc;

            // Trigger reloading of the image
            ChangeFile(null, null);
        }
示例#2
0
        private void ChangeFile(object sender, EventArgs e)
        {
            // When the file is changed, we need to display the new file.
            string filename = CB_File.Text;
            int    entry    = -1;
            // Find entry in darc
            var darc = darcs[CB_DARC.SelectedIndex];

            for (int i = 0; i < darc.Entries.Length; i++)
            {
                if (darc.FileNameTable[i].FileName != filename)
                {
                    continue;
                }
                entry = i;
                break;
            }

            if (entry < 0)
            {
                throw new Exception("File not found!?");
            }

            // Load file
            var en   = darc.Entries[entry];
            var data = new byte[en.DataLength];
            var ofs  = en.DataOffset - darc.Header.FileDataOffset;

            Array.Copy(darc.Data, ofs, data, 0, data.Length);
            BCLIM bclim   = BCLIM.Analyze(data, filename);
            Image CropBMP = bclim.GetBitmap();

            PB_Image.Image = CropBMP;
            // store image locally for saving if need be
            currentBytes = data;

            L_Dimensions.Text = $"Dimensions: {PB_Image.Width}w && {PB_Image.Height}h";
        }