private byte[] CompressImageData(string ssid, Bitmap bmp, out bool isBackground) { byte[] bsData; isBackground = true; try { int width = bmp.Width; int height = bmp.Height; bool indexed = (bmp.PixelFormat == PixelFormat.Format8bppIndexed); byte[] data = ImageCompressEngine.ExtractImageData(bmp); if (_background != null) { if (width == _background.Width && height == _background.Height || indexed != _background.IsIndexed) { Debug.Assert(_background.Data.Length == data.Length); float diff = ImageCompressEngine.XorImageData(_background.Data, 0, data, 0, _background.Data.Length); if (diff < _ratio) { bsData = Compress.Deflate(data, true); isBackground = false; } else { data = ImageCompressEngine.ExtractImageData(bmp); UpdateBackground(ssid, width, height, indexed, data); bsData = Compress.Deflate(data, true); } } else { UpdateBackground(ssid, width, height, indexed, data); bsData = Compress.Deflate(data, true); } } else { UpdateBackground(ssid, width, height, indexed, data); bsData = Compress.Deflate(data, true); } } catch (Exception ex) { bsData = null; TraceLogger.Instance.WriteException(ex); throw; } return(bsData); }