我有一个WriteableBitmap,我使用一个不安全的方法来绘制像素.基本部分看起来像这样:
private unsafe void DrawBitmap(WriteableBitmap bitmap, byte[] pixels)
{
// Boilerplate omitted...
fixed (byte* pPixels = pixels)
{
for (int y = 0; y < height; y++)
{
var row = pPixels + (y * width);
for (int x = 0; x < width; x++)
{
*(row + x) = color[y + height * x];
}
}
}
bitmap.WritePixels(new Int32Rect(0, 0, width, height), pixels, width*pf.BitsPerPixel/8, 0);
}
然而,不确定用户想要绘制的是字节类型,并且使该方法通用(即,DrawBitmap< T>)是有意义的,但是如何使指针pPixel类型为T *?
还有其他一些技巧会让我的DrawBitmap变得通用吗?