本文整理汇总了C#中Octree.GetColorIndexTable方法的典型用法代码示例。如果您正苦于以下问题:C# Octree.GetColorIndexTable方法的具体用法?C# Octree.GetColorIndexTable怎么用?C# Octree.GetColorIndexTable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Octree
的用法示例。
在下文中一共展示了Octree.GetColorIndexTable方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReduceColors
private static unsafe System.Drawing.Image ReduceColors(Bitmap bitmap, int maxColors, int numBits, Color transparentColor)
{
byte* numPtr;
if ((numBits < 3) || (numBits > 8))
{
throw new ArgumentOutOfRangeException("numBits");
}
if (maxColors < 0x10)
{
throw new ArgumentOutOfRangeException("maxColors");
}
int width = bitmap.Width;
int height = bitmap.Height;
Octree octree = new Octree(maxColors, numBits, transparentColor);
for (int i = 0; i < width; i++)
{
for (int k = 0; k < height; k++)
{
octree.AddColor(bitmap.GetPixel(i, k));
}
}
ColorIndexTable colorIndexTable = octree.GetColorIndexTable();
Bitmap bitmap2 = new Bitmap(width, height, PixelFormat.Format8bppIndexed);
ColorPalette palette = bitmap2.Palette;
Rectangle rect = new Rectangle(0, 0, width, height);
BitmapData bitmapdata = bitmap2.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);
IntPtr ptr = bitmapdata.Scan0;
if (bitmapdata.Stride > 0)
{
numPtr = (byte*) ptr.ToPointer();
}
else
{
numPtr = (byte*) (ptr.ToPointer() + (bitmapdata.Stride * (height - 1)));
}
int num5 = Math.Abs(bitmapdata.Stride);
for (int j = 0; j < height; j++)
{
for (int m = 0; m < width; m++)
{
byte* numPtr2 = (numPtr + (j * num5)) + m;
Color pixel = bitmap.GetPixel(m, j);
byte num8 = (byte) colorIndexTable[pixel];
numPtr2[0] = num8;
}
}
colorIndexTable.CopyToColorPalette(palette);
bitmap2.Palette = palette;
bitmap2.UnlockBits(bitmapdata);
return bitmap2;
}