Yes the stride can be negative. One problem in your code, however, is you're not using the correct LockBits method. You're using the one marked "
This version of the LockBits method is intended to be used with a flags value of ImageLockMode::UserInputBuffer".
Maybe try this, adjusted to use correct pointer arithmetic and LockBits method...
Bitmap ^a = gcnew Bitmap(width,height,System::Drawing::Imaging::PixelFormat::Format16bppGrayScale);
System::Drawing::Rectangle b(0,0,width,height);
BitmapData ^bitmapData = a->LockBits(b, System::Drawing::Imaging::ImageLockMode::WriteOnly, a->PixelFormat);
unsigned char *ptr = (unsigned char *)bitmapData->Scan0.ToPointer();
for (int i = 0;i < height; i++)
{
unsigned short int * LinePtr = (unsigned short int *)(ptr + (i * bitmapData->Stride));
for(int j = 0; j < width; j++)
{
LinePtr[j]=0; }
}
a->UnlockBits(bitmapData);
return a;