Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static Bitmap ConvertTo(byte[] data)
- {
- int pixelCount = (data.Length / 4) + 2;
- int l = (int)Math.Sqrt(pixelCount) + 1;
- int k = 0;
- Bitmap b = new Bitmap(l, l);
- byte[] n = new byte[l * l * 4];
- Buffer.BlockCopy(BitConverter.GetBytes(data.Length), 0, n, 0, 4);
- Buffer.BlockCopy(data, 0, n, 4, data.Length);
- for (int x = 0; x < l; x++)
- {
- for (int y = 0; y < l; y++)
- {
- int argb = BitConverter.ToInt32(n, k);
- k += 4;
- Color c = Color.FromArgb(argb/*n[k++], n[k++], n[k++], n[k++]*/);
- b.SetPixel(x, y, c);
- }
- }
- return b;
- }
- private static byte[] ConvertFromBmp(Bitmap b)
- {
- int l = b.Width;
- int n = l * l * 4;
- byte[] buff = new byte[n];
- int k = 0;
- for (int x = 0; x < l; x++)
- {
- for (int y = 0; y < l; y++)
- {
- Buffer.BlockCopy(BitConverter.GetBytes(b.GetPixel(x, y).ToArgb()), 0, buff, k, 4);
- k += 4;
- }
- }
- int len = BitConverter.ToInt32(buff, 0);
- byte[] f = new byte[len];
- Buffer.BlockCopy(buff, 4, f, 0, f.Length);
- return f;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement