本文整理汇总了C#中System.Drawing.Color.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:C# System.Drawing.Color.CopyTo方法的具体用法?C# System.Drawing.Color.CopyTo怎么用?C# System.Drawing.Color.CopyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Color
的用法示例。
在下文中一共展示了System.Drawing.Color.CopyTo方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetFrameBuffer
public System.Drawing.Bitmap GetFrameBuffer()
{
ushort widthInWords;
ushort heightInPixels;
uint[] buf;
System.Drawing.Bitmap bmp = null;
System.Drawing.Imaging.PixelFormat pixelFormat = System.Drawing.Imaging.PixelFormat.DontCare;
if (GetFrameBuffer(out widthInWords, out heightInPixels, out buf))
{
CLRCapabilities.LCDCapabilities lcdCaps = Capabilities.LCD;
int pixelsPerWord = 32 / (int)lcdCaps.BitsPerPixel;
System.Diagnostics.Debug.Assert(heightInPixels == lcdCaps.Height);
System.Diagnostics.Debug.Assert(widthInWords == (lcdCaps.Width + pixelsPerWord - 1) / pixelsPerWord);
System.Drawing.Color[] colors = null;
switch (lcdCaps.BitsPerPixel)
{
case 1:
pixelFormat = System.Drawing.Imaging.PixelFormat.Format1bppIndexed;
colors = new System.Drawing.Color[] { System.Drawing.Color.White, System.Drawing.Color.Black };
Adjust1bppOrientation(buf);
break;
case 4:
case 8:
//Not tested
int cColors = 1 << (int)lcdCaps.BitsPerPixel;
pixelFormat = (lcdCaps.BitsPerPixel == 4) ? System.Drawing.Imaging.PixelFormat.Format4bppIndexed : System.Drawing.Imaging.PixelFormat.Format8bppIndexed;
colors = new System.Drawing.Color[cColors];
for (int i = 0; i < cColors; i++)
{
int intensity = 256 / cColors * i;
colors[i] = System.Drawing.Color.FromArgb(intensity, intensity, intensity);
}
break;
case 16:
pixelFormat = System.Drawing.Imaging.PixelFormat.Format16bppRgb565;
break;
default:
System.Diagnostics.Debug.Assert(false);
return null;
}
System.Drawing.Imaging.BitmapData bitmapData = null;
try
{
bmp = new System.Drawing.Bitmap((int)lcdCaps.Width, (int)lcdCaps.Height, pixelFormat);
System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, (int)lcdCaps.Width, (int)lcdCaps.Height);
if (colors != null)
{
System.Drawing.Imaging.ColorPalette palette = bmp.Palette;
colors.CopyTo(palette.Entries, 0);
bmp.Palette = palette;
}
bitmapData = bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.WriteOnly, pixelFormat);
IntPtr data = bitmapData.Scan0;
unsafe
{
fixed (uint* pbuf = buf)
{
uint* src = (uint*)pbuf;
uint* dst = (uint*)data.ToPointer();
for (int i = buf.Length; i > 0; i--)
{
*dst = *src;
dst++;
src++;
}
}
}
}
finally
{
if (bitmapData != null)
{
bmp.UnlockBits(bitmapData);
}
}
}
return bmp;
}