public Bitmap Import() { 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); Bitmap Picture = new Bitmap(Header.Width, Header.Heigth, System.Drawing.Imaging.PixelFormat.Format32bppArgb); for (int y = 0; y < Header.Heigth; y++) { for (int x = 0; x < Header.Width; x++) { Pixel Pixel = new Pixel(); Reader.ReadStruct(ref Pixel); Picture.SetPixel(x, y, Color.FromArgb(Pixel.A, Pixel.R, Pixel.G, Pixel.B)); } } Reader.Close(); return(Picture); }
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); }