我现在有这个;
private const int PixelSizeBGR = 3;
[StructLayout(LayoutKind.Explicit)]
private unsafe struct BGR5
{
[FieldOffset(0)]
private fixed byte bgr[PixelSizeBGR * 5];
public BGR5(byte b, byte g, byte r)
{
fixed (byte* v = bgr)
{
int num = 0;
do
{
v[num++] = b; v[num++] = g; v[num++] = r;
} while (num < (PixelSizeBGR * 5));
}
}
}
[StructLayout(LayoutKind.Explicit)]
private unsafe struct BGR3
{
[FieldOffset(0)]
private fixed byte bgr[PixelSizeBGR * 3];
public BGR3(byte b, byte g, byte r)
{
fixed (byte* v = bgr)
{
int num = 0;
do
{
v[num++] = b; v[num++] = g; v[num++] = r;
} while (num < (PixelSizeBGR * 3));
}
}
}
你可以看到我认为的模式。
有没有办法让它变得动态,因为我可能会发现我需要更多这些?
还是有其他选择?
实际例子;
之前,24000 x 24000 像素位图,2151 毫秒
byte* row = (byte*)bmd.Scan0;
/*** stuff ***/
Offset1 = ((CurrentPos / GridX) * FullRow) + ((CurrentPos % GridX) * FullSquare);
for (k = PixelSize; k <= w; k += PixelSize)
{
Offset1 += PixelSize;
for (l = Stride; l <= h; l += Stride)
{
row[l + Offset1] = 0; //b
row[l + Offset1 + 1] = 255; //g
row[l + Offset1 + 2] = 255; //r
}
}
/*** more stuff ***/
之后,24000 x 24000 像素位图,944 毫秒
byte* row = (byte*)bmd.Scan0;
/*** stuff ***/
np5.Set(0, 255, 255);
Offset1 = ((CurrentPos / GridX) * FullRow) + ((CurrentPos % GridX) * FullSquare) + PixelSizeBGR;
h = Stride;
do
{
*((BGR5*)(row + h + Offset1)) = np5;
h += Stride;
} while (h < FullRow);
/*** more stuff ***/
AFTER 速度快 50% 以上