public override byte[] ToArray()
{
int size = Marshal.SizeOf(TGAHeader);
if (size != headSize)
throw new FormatException("Incorrect TGA header size");
byte[] head = new byte[size];
IntPtr ptr = Marshal.AllocHGlobal(size);
Marshal.StructureToPtr(TGAHeader, ptr, true);
Marshal.Copy(ptr, head, 0, size);
Marshal.FreeHGlobal(ptr);
byte[] total = new byte[headSize + dataSize];
head.CopyTo(total, 0);
imgData.CopyTo(total, headSize);
return total;
}