public Collect8bppPixelValues ( List |
||
points | List |
List of coordinates to collect pixels' value from. |
Результат | byte[] |
public byte[] Collect8bppPixelValues(List<IntPoint> points)
{
int pixelSize = Bitmap.GetPixelFormatSize(pixelFormat) / 8;
if ((pixelFormat == PixelFormat.Format16bppGrayScale) || (pixelSize > 4))
{
throw new UnsupportedImageFormatException("Unsupported pixel format of the source image. Use Collect16bppPixelValues() method for it.");
}
byte[] pixelValues = new byte[points.Count * ((pixelFormat == PixelFormat.Format8bppIndexed) ? 1 : 3)];
unsafe
{
byte* basePtr = (byte*)imageData.ToPointer();
byte* ptr;
if (pixelFormat == PixelFormat.Format8bppIndexed)
{
int i = 0;
foreach (IntPoint point in points)
{
ptr = basePtr + stride * point.Y + point.X;
pixelValues[i++] = *ptr;
}
}
else
{
int i = 0;
foreach (IntPoint point in points)
{
ptr = basePtr + stride * point.Y + point.X * pixelSize;
pixelValues[i++] = ptr[RGB.R];
pixelValues[i++] = ptr[RGB.G];
pixelValues[i++] = ptr[RGB.B];
}
}
}
return pixelValues;
}