C# CUR类实现代码

2019-05-11 23:49:07王旭

_Memory.Write(BitConverter.GetBytes((ushort)m_CurList.Count), 0, 2);
List<byte[]> _ImageByteList = new List<byte[]>();
m_CurHead.ImageRVA = (uint)m_CurList.Count * 16 + 6;
for (int i = 0; i != m_CurList.Count; i++)
{
if (m_CurList[i].Width > 255 || m_CurList[i].Height > 255)
{
_Memory.Close();
throw new Exception("图形文件过大!");
}
byte[] _ImageSize = GetImageBytes(i);
m_CurHead.ImageHeight = (byte)CurImage[i].Height;
m_CurHead.ImageWidth = (byte)CurImage[i].Width;
m_CurHead.ImageRVA += m_CurHead.ImageLength;
m_CurHead.ImageLength = (uint)_ImageSize.Length;
_ImageByteList.Add(_ImageSize);
_Memory.Write(m_CurHead.GetImageByte(), 0, 16);
}
for (int i = 0; i != _ImageByteList.Count; i++)
{
byte[] _Height = BitConverter.GetBytes((uint)(m_CurList[i].Height * 2));
_ImageByteList[i][8] = _Height[0];
_ImageByteList[i][9] = _Height[1];
_ImageByteList[i][10] = _Height[2];
_ImageByteList[i][11] = _Height[3];
_Memory.Write(_ImageByteList[i], 0, _ImageByteList[i].Length);
}
return _Memory;
}
/// <summary>
/// CUR图形
/// </summary>
public IList<Image> CurImage { get { return m_CurList; } set { m_CurList = value; } }
public byte[] GetImageBytes(int p_ImageIndex)
{
MemoryStream _Memory = new MemoryStream();
if (m_CurList[p_ImageIndex].PixelFormat != PixelFormat.Format32bppArgb)
{
Bitmap _Image = new Bitmap(m_CurList[p_ImageIndex].Width, m_CurList[p_ImageIndex].Height, PixelFormat.Format32bppArgb);
Graphics _Graphcis = Graphics.FromImage(_Image);
_Graphcis.Dispose();
_Image.Save(_Memory, ImageFormat.Bmp);
}
else
{
m_CurList[p_ImageIndex].Save(_Memory, ImageFormat.Bmp);
}
byte[] _Test = _Memory.ToArray();
byte[] _ImageBytes = new byte[_Memory.Length - 0x0E];
_Memory.Position = 0x0E;
_Memory.Read(_ImageBytes, 0, _ImageBytes.Length);
return _ImageBytes;
}
}
}