How can I create a pointer to C #?

I have WriteableBitmapone that I use an unsafe method to build pixels. The essential part is as follows:

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);
}

However, it is unclear that what the user wants to build is of type byte, and it would be advisable to make this method general (i.e. DrawBitmap<T>), but how can I make a pPixelstype pointer T*?

Is there any other trick that will do my DrawBitmapcommon?

+5
source share
1 answer

Consider using overloads .

public void MethodA(byte[] pPixels) {}
public void MethodA(int[] pPixels {}
//etc...
+3
source

All Articles