示例#1
0
        public Bitmap Export(byte[] Texture, string name = "")
        {
            StructReader Reader = new StructReader(new MemoryStream(Texture));
            CZ1Header    Header = new CZ1Header();

            Reader.ReadStruct(ref Header);

            if (Header.Signature != "CZ1\x0")
            {
                throw new BadImageFormatException();
            }

            Reader.Seek(Header.HeaderLength, SeekOrigin.Begin);
            Bitmap Picture = new Bitmap(Header.Width, Header.Heigth, PixelFormat.Format32bppArgb);

            if (Header.Colorbits == 4)//4bit
            {
                //字库格式
                //System.Diagnostics.Debug.WriteLine(4);
                //表
                Pixel32_BGRA[] ColorPanel = new Pixel32_BGRA[16];
                Pixel32_BGRA   Pixel      = new Pixel32_BGRA();
                for (int i = 0; i < ColorPanel.Length; i++)
                {
                    Reader.ReadStruct(ref Pixel);
                    ColorPanel[i] = Pixel;
                }

                //lmz解压
                var bytes = Decompress(Reader, name);

                //解压后的像素
                Queue <int> queue = new Queue <int>();
                foreach (var b in bytes)
                {
                    int low4bit  = b & 0x0F;
                    int high4bit = (b & 0xF0) >> 4;
                    queue.Enqueue(low4bit);
                    queue.Enqueue(high4bit);
                }

                for (int y = 0; y < Header.Heigth; y++)
                {
                    for (int x = 0; x < Header.Width; x++)
                    {
                        int index = queue.Dequeue();
                        Picture.SetPixel(x, y, Color.FromArgb(ColorPanel[index].A, ColorPanel[index].R, ColorPanel[index].G, ColorPanel[index].B));
                    }
                }
            }
            else if (Header.Colorbits == 8)//8bit
            {
                System.Diagnostics.Debug.WriteLine(8);
                Pixel32_BGRA[] ColorPanel = new Pixel32_BGRA[256];
                Pixel32_BGRA   Pixel      = new Pixel32_BGRA();
                for (int i = 0; i < ColorPanel.Length; i++)
                {
                    Reader.ReadStruct(ref Pixel);
                    ColorPanel[i] = Pixel;
                }

                var         bytes = Decompress(Reader);
                Queue <int> queue = new Queue <int>();
                foreach (var b in bytes)
                {
                    queue.Enqueue(b);
                }
                // var ie = bytes.GetEnumerator();
                for (int y = 0; y < Header.Heigth; y++)
                {
                    for (int x = 0; x < Header.Width; x++)
                    {
                        int index = queue.Dequeue();
                        //int index = BitConverter.ToInt16(new byte[] { ie.Current, 0x00 }, 0);
                        Picture.SetPixel(x, y, Color.FromArgb(ColorPanel[index].A, ColorPanel[index].R, ColorPanel[index].G, ColorPanel[index].B));
                    }
                }
            }
            else if (Header.Colorbits == 24)
            {
                System.Diagnostics.Debug.WriteLine(24);
                List <byte> bytes = (List <byte>)Decompress(Reader);
                Reader = new StructReader(new MemoryStream(bytes.ToArray()));

                for (int y = 0; y < Header.Heigth; y++)
                {
                    for (int x = 0; x < Header.Width; x++)
                    {
                        Pixel24_RGB Pixel = new Pixel24_RGB();
                        Reader.ReadStruct(ref Pixel);
                        Picture.SetPixel(x, y, Color.FromArgb(Pixel.R, Pixel.G, Pixel.B));
                    }
                }
            }
            else if (Header.Colorbits == 32)//32
            {
                System.Diagnostics.Debug.WriteLine(32);
                List <byte> bytes = (List <byte>)Decompress(Reader);
                Reader = new StructReader(new MemoryStream(bytes.ToArray()));


                for (int y = 0; y < Header.Heigth; y++)
                {
                    for (int x = 0; x < Header.Width; x++)
                    {
                        Pixel32_RGBA Pixel = new Pixel32_RGBA();
                        Reader.ReadStruct(ref Pixel);
                        Picture.SetPixel(x, y, Color.FromArgb(Pixel.A, Pixel.R, Pixel.G, Pixel.B));
                    }
                }
            }
            Reader.Close();
            return(Picture);
        }
示例#2
0
        public Bitmap Export(byte[] Texture, string name = "")
        {
            StructReader Reader = new StructReader(new MemoryStream(Texture));
            CZ0Header    Header = new CZ0Header();

            Reader.ReadStruct(ref Header);

            if (Header.Signature != "CZ0\x0")
            {
                throw new BadImageFormatException();
            }

            Reader.Seek(Header.HeaderLength, SeekOrigin.Begin);
            CZ0HeaderInfo cz0HeaderInfo = new CZ0HeaderInfo();

            cz0HeaderInfo.cz0Header = Header;
            Bitmap Picture = new Bitmap(Header.Width, Header.Heigth, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            if (Header.Colorbits == 8)
            {
                System.Diagnostics.Debug.WriteLine(8);
                Pixel32_BGRA[] ColorPanel = new Pixel32_BGRA[256];
                Pixel32_BGRA   Pixel      = new Pixel32_BGRA();
                for (int i = 0; i < ColorPanel.Length; i++)
                {
                    Reader.ReadStruct(ref Pixel);
                    ColorPanel[i] = Pixel;
                }
                cz0HeaderInfo.ColorPanel = ColorPanel;
                for (int y = 0; y < Header.Heigth; y++)
                {
                    for (int x = 0; x < Header.Width; x++)
                    {
                        byte tmp = 0;
                        Reader.ReadStruct(ref tmp);
                        uint index = tmp;
                        Picture.SetPixel(x, y, Color.FromArgb(ColorPanel[index].A, ColorPanel[index].R, ColorPanel[index].G, ColorPanel[index].B));
                    }
                }
            }
            else if (Header.Colorbits == 24)
            {
                for (int y = 0; y < Header.Heigth; y++)
                {
                    for (int x = 0; x < Header.Width; x++)
                    {
                        Pixel24_RGB Pixel = new Pixel24_RGB();
                        Reader.ReadStruct(ref Pixel);
                        Picture.SetPixel(x, y, Color.FromArgb(Pixel.R, Pixel.G, Pixel.B));
                    }
                }
            }
            else if (Header.Colorbits == 32)
            {
                for (int y = 0; y < Header.Heigth; y++)
                {
                    for (int x = 0; x < Header.Width; x++)
                    {
                        Pixel32_RGBA Pixel = new Pixel32_RGBA();
                        Reader.ReadStruct(ref Pixel);
                        Picture.SetPixel(x, y, Color.FromArgb(Pixel.A, Pixel.R, Pixel.G, Pixel.B));
                    }
                }
            }
            Reader.Close();
            string json = JsonConvert.SerializeObject(cz0HeaderInfo, Formatting.Indented);

            File.WriteAllText(name + ".json", json);
            return(Picture);
        }