Home All Groups Group Topic Archive Search About

Why the Marshalling / Copying?

Author
21 May 2006 8:13 PM
bern11
The following is a snippet right out of the LockBits help:


IntPtr ptr = bmpData->Scan0;
....
....

    // Copy the RGB values into the array.
    System::Runtime::InteropServices::Marshal::Copy( ptr, rgbValues, 0,
bytes );

    // Set every red value to 255.
    for ( int counter = 0; counter < rgbValues->Length; counter += 3 )
       rgbValues[ counter ] = 255;

    // Copy the RGB values back to the bitmap
    System::Runtime::InteropServices::Marshal::Copy( rgbValues, 0, ptr,
bytes );


It is a copy - modify - copy back sequence.  My question:  why bother?
Why not simply cast a pointer:

cPixel = (char *)bmpData->Scan0.ToInt32();

and work directly on the data?  What are the risks?

AddThis Social Bookmark Button