Reputation: 377
I tried to translate this code to vb.net using Marshal.copy
but I can't get it to work
for (int y = 0; y < bitmapdata.Height; y++)
{
byte* destPixels = (byte*)bitmapdata.Scan0 + (y * bitmapdata.Stride);
for (int x = 0; x < bitmapdata.Width; x++)
{
destPixels[x * PixelSize] = contrast_lookup[destPixels[x * PixelSize]]; // B
destPixels[x * PixelSize + 1] = contrast_lookup[destPixels[x * PixelSize + 1]]; // G
destPixels[x * PixelSize + 2] = contrast_lookup[destPixels[x * PixelSize + 2]]; // R
//destPixels[x * PixelSize + 3] = contrast_lookup[destPixels[x * PixelSize + 3]]; //A
}
}
My problem is this line:
byte* destPixels = (byte*)bitmapdata.Scan0 + (y * bitmapdata.Stride);
Upvotes: 0
Views: 370
Reputation: 613013
Assuming that you have Scan0
as an IntPtr
then the naive translation to C# is simply:
IntPtr destPixels = Scan0 + y*stride;
The players here are:
Scan0
: a pointer to the first scanline, i.e. the beginning of the pixel data.y
: the row number.stride
: the number of bytes in a row of pixels.destPixels
: a pointer to the beginning of row y
.But this would be under the assumption that you were using unmanaged memory for destPixels
. I don't know whether or not you are. If you are using managed memory, then the translation would differ. If you want more help you need to tell us about the types that your managed version uses.
Upvotes: 2