public static PcxFile FromBitmap(Bitmap bmp)
        {
            PcxFile pcf = new PcxFile(new byte[16]);

            pcf.LoadBitmap(bmp, false);
            return(pcf);
        }
Exemple #2
0
 public byte[] GetBitmap24Data(Stream stream, out int width)
 {
     width = 0;
     if (Extension == "PCX")
     {
         byte[] array;
         if (newVal == null)
         {
             byte[] bts = new byte[Size];
             stream.Position = Offset;
             stream.Read(bts, 0, Size);
             array = ZlibWrapper.UnZlib(bts);
         }
         else
         {
             array = newVal;
         }
         var file = new PcxFile(array);
         try
         {
             return(file.GetBitmap24Bytes(out width));
         }
         catch
         {
             return(null);
         }
     }
     return(null);
 }
        private void ldBmp_Click(object sender, EventArgs e)
        {
            var rec = selectedLodFile.GetRecord(lbFiles.SelectedItem.ToString());

            if (rec.Extension == "TXT")
            {
                string filt = ofd.Filter;
                ofd.Filter = "Text |*.txt";
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    var bytes = File.ReadAllBytes(ofd.FileName);
                    rec.ApplyChanges(bytes);
                }
                ofd.Filter = filt;
            }
            else if (rec.Extension == "PCX")
            {
                string filt = ofd.Filter;
                ofd.Filter = "Images |*.bmp;*.jpeg;*.jpg;*.gif";
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    var pcx = PcxFile.FromBitmap((Bitmap)Image.FromFile(ofd.FileName));
                    rec.ApplyChanges(pcx.GetBytes);
                }
                ofd.Filter = filt;
            }
        }
Exemple #4
0
        public Bitmap GetBitmap(Stream stream)
        {
            if (Extension == "PCX")
            {
                byte[] array;
                if (newVal == null)
                {
                    if (Size != 0)
                    {
                        byte[] bts = new byte[Size];
                        stream.Position = Offset;
                        stream.Read(bts, 0, Size);
                        array = ZlibWrapper.UnZlib(bts);
                    }
                    else if (RealSize != 0)
                    {
                        array           = new byte[RealSize];
                        stream.Position = Offset;
                        stream.Read(array, 0, RealSize);
                    }
                    else
                    {
                        throw new Exception("Image size unknown");
                    }
                }
                else
                {
                    array = newVal;
                }

                var file = new PcxFile(array);
                try
                {
                    return(file.GetBitmap());
                }
                catch (Exception ex)
                {
                    return(null);
                }
            }
            return(null);
        }
Exemple #5
0
        public static void SaveLocalChanges(Heroes3Master master)
        {
            var lod1 = master.Resolve(TXT_BIOGRAPHIES_FNAME);
            var lod2 = master.Resolve(H_SPECS);
            var lod3 = master.Resolve(H_HEROES);

            StringBuilder bios, spec, traits;

            bios   = new StringBuilder();
            spec   = new StringBuilder();
            traits = new StringBuilder();
            spec.AppendLine(spec_rows[0] + "\r\n" + spec_rows[1]);
            traits.AppendLine(hero_rows[0] + "\r\n" + hero_rows[1]);

            for (int i = 0; i < HeroesOrder.Length; i++)
            {
                bios.AppendLine(AllHeroes[i].Biography);
                spec.AppendLine(AllHeroes[i].Speciality);
                traits.Append(AllHeroes[i].Name);
                traits.Append('\t');
                traits.Append(AllHeroes[i].LowStack1);
                traits.Append('\t');
                traits.Append(AllHeroes[i].HighStack1);
                traits.Append('\t');
                traits.Append("cr1");
                traits.Append('\t');
                traits.Append(AllHeroes[i].LowStack2);
                traits.Append('\t');
                traits.Append(AllHeroes[i].HighStack2);
                traits.Append('\t');
                traits.Append("cr2");
                traits.Append('\t');
                traits.Append(AllHeroes[i].LowStack3);
                traits.Append('\t');
                traits.Append(AllHeroes[i].HighStack3);
                traits.Append('\t');
                traits.AppendLine("cr3");
                if (AllHeroes[i].Large != null)
                {
                    var rec = master.ResolveWith(HeroesOrder[AllHeroes[i].ImageIndex]);
                    rec.ApplyChanges(PcxFile.FromBitmap(AllHeroes[i].Large).GetBytes);
                }
                if (AllHeroes[i].Small != null)
                {
                    var rec = master.ResolveWith(HeroesOrder[AllHeroes[i].ImageIndex].Replace("HPL", "HPS"));
                    rec.ApplyChanges(PcxFile.FromBitmap(AllHeroes[i].Small).GetBytes);
                }
            }
            for (int i = HeroesOrder.Length; i < bio_rows.Length; i++)
            {
                bios.AppendLine(bio_rows[i]);
                if (i + 2 < spec_rows.Length)
                {
                    spec.AppendLine(spec_rows[2 + i]);
                }
                if (i + 2 < hero_rows.Length)
                {
                    traits.AppendLine(hero_rows[2 + i]);
                }
            }

            lod1[TXT_BIOGRAPHIES_FNAME].ApplyChanges(Encoding.Default.GetBytes(bios.ToString()));
            lod2[H_SPECS].ApplyChanges(Encoding.Default.GetBytes(spec.ToString()));
            lod3[H_HEROES].ApplyChanges(Encoding.Default.GetBytes(traits.ToString()));
        }