using System.Drawing.Imaging;
using ICSharpCode.SharpZipLib.Zip.Compression;
using System.Runtime.InteropServices;
public static Bitmap ArrayToBitmap(byte[] bytes, int width, int height, System.Drawing.Imaging.PixelFormat pixelFormat)
var image = new Bitmap(width, height, pixelFormat);
var imageData = image.LockBits(new System.Drawing.Rectangle(0, 0, image.Width, image.Height),
ImageLockMode.ReadWrite, pixelFormat);
Marshal.Copy(bytes, 0, imageData.Scan0, bytes.Length);
image.UnlockBits(imageData);
public static byte[] Decompress(byte[] data)
Inflater inflater = new Inflater(true);
byte[] buf = new byte[1024];
using (MemoryStream memory = new MemoryStream())
while (!inflater.IsFinished)
count = inflater.Inflate(buf);
memory.Write(buf, 0, count);
count = inflater.Inflate(buf);
memory.Write(buf, 0, count);
public static byte[] Compress(byte[] data)
Deflater deflater = new Deflater(Deflater.DEFAULT_COMPRESSION, true);
deflater.SetStrategy(DeflateStrategy.Default);
byte[] buf = new byte[1024];
using (MemoryStream memory = new MemoryStream())
while (!deflater.IsFinished)
count = deflater.Deflate(buf);
memory.Write(buf, 0, count);
count = deflater.Deflate(buf);
memory.Write(buf, 0, count);
public static string HexBytes(byte[] bytes) {
return string.Join(" ", bytes.Select(b => string.Format("{0:x2}", b)).ToArray());
public static void Main(string[] args)
string zipString = "eJztlDEOgzAMRY0YsqDmBvVRci02OBpH4QiMDBHpVj+QojaVEFDxp6fIdr4dKyJfy/UHsKaUSvgon1vhvMrEe7CCO5SJhvWMMiNSB+OAMotFpAieMoyrkLuuybvogd7oedULe2TvnAlnxRl+VPGeVKM7FcvkydZZDMYdHiaANbMbv6t0nk9p3f+wkHdVUxsrtkH98OYAVmf8yP4+t66iF1UlgLg=";
var a = Convert.FromBase64String(zipString);
var z64 = a.Skip(2).ToArray();
byte[] uzipZ64 = Decompress(z64);
byte[] new_z64 = Compress(uzipZ64);
byte[] newData = new byte[new_z64.Length + 2];
Array.Copy(new_z64, 0, newData, 2, new_z64.Length);
string newZipString = Convert.ToBase64String(newData);
bool isSame = zipString.Equals(newZipString);
Console.WriteLine(zipString);
Console.WriteLine(newZipString);
Console.WriteLine(HexBytes(a));
Console.WriteLine(HexBytes(newData));
Console.WriteLine(HexBytes(a));
Console.WriteLine(HexBytes(newData));