Esempio n. 1
0
        private void ExportPNGfromPIX(byte[] data, string pixname, string output)
        {
            if (data == null)
            {
                return;
            }
            PIXFile px  = new PIXFile(data);
            string  dir = output;

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            if (px.headers.Count > 1)
            {
                dir += pixname;
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                dir += "\\";
            }
            for (int i = 0; i < px.headers.Count; i++)
            {
                PIXFile.PIXHeader h    = px.headers[i];
                PIXFile.PIXData   d    = px.images[i];
                Bitmap            bmp  = PIXFile.MakeBitmap(h, d);
                string            name = MakeName(dir + Sanitize(h.name));
                bmp.Save(name);
                Log.WriteLine("Saved " + name);
            }
        }
Esempio n. 2
0
 private void importPNGToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (listBox1.SelectedIndex != -1 && comboBox1.SelectedIndex != -1)
     {
         string  s      = listBox1.SelectedItem.ToString();
         byte[]  pxData = LoadFile(s);
         PIXFile px     = new PIXFile(pxData);
         if (px == null)
         {
             return;
         }
         OpenFileDialog d = new OpenFileDialog();
         d.Filter = "*.png|*.png";
         if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {
             Bitmap            bmp = new Bitmap(d.FileName);
             PIXFile.PIXHeader h   = px.headers[comboBox1.SelectedIndex];
             if (bmp.Width != h.Width || bmp.Height != h.Height)
             {
                 MessageBox.Show("Imported image size doesnt match! (" + bmp.Width + "x" + bmp.Height + " vs " + h.Width + "x" + h.Height + ")");
                 return;
             }
             byte[] data  = PIXFile.MakePixdata(h, bmp);
             int    start = (int)px.images[comboBox1.SelectedIndex]._fileOffset + 12;
             for (int i = 0; i < data.Length; i++)
             {
                 pxData[start + i] = data[i];
             }
             if (s.Contains(">"))
             {
                 IdxFile       idf;
                 FileReference r;
                 FileSystem.FindFile(s, out idf, out r);
                 if (idf == null || r == null)
                 {
                     return;
                 }
                 uint ucsize = (uint)pxData.Length;
                 if (r.compression != 0)
                 {
                     pxData = Helper.CompressRLE(pxData, r.compression);
                 }
                 idf.SaveEntry(r, pxData, ucsize);
             }
             else
             {
                 File.WriteAllBytes(s, pxData);
             }
             Log.WriteLine("Saved to " + s);
         }
     }
 }
Esempio n. 3
0
 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
 {
     try
     {
         int n = comboBox1.SelectedIndex;
         if (n == -1)
         {
             return;
         }
         PIXFile.PIXHeader h = currentPix.headers[n];
         PIXFile.PIXData   d = currentPix.images[n];
         pb1.Image = PIXFile.MakeBitmap(h, d);
     }
     catch { }
 }
Esempio n. 4
0
 private void listBox1_SelectedIndexChanged_1(object sender, EventArgs e)
 {
     try
     {
         string s = listBox1.SelectedItem.ToString();
         currentPix = new PIXFile(LoadFile(s));
         comboBox1.Items.Clear();
         int count = 1;
         foreach (PIXFile.PIXHeader h in currentPix.headers)
         {
             comboBox1.Items.Add(count++ + "/" + currentPix.headers.Count + " " + h.name);
         }
         if (comboBox1.Items.Count != 0)
         {
             comboBox1.SelectedIndex = 0;
         }
     }
     catch { }
 }