I have imported a corporate image handling COM object in my C#
project.
To access in a fast way the memory of the image there is a method that
returns a pointer to the memory (in byte) of the underlying image.
This method can be used to read as well to rewrite the pixel values.
In the interface .idl file the method is declared as:
[helpstring("Get a pointer to the pixels of a plane")]
HRESULT GetPlane([out,size_is(,*dim)] BYTE ** pPlane,
[out,unique] long *dim);
C# imports the method as:
void GetPlane(intPtr pPlane, out int dim)
I haven't found a way to directly access (read and write) the memory
pointed by intPtw without the need of copying to managed memory.
An example of error:
int planeSize;
byte b;
int v;
unsafe
{
IntPtr pPlane = new IntPtr((void*)&b); // here I tried with pPlane =
new IntPtr.Zero but gave me NullReferenceException
img.GetPlane(pPlane, out planeSize);
byte* pByte = (byte*)pPlane.ToPointer();
for (int i = 0; i < planeSize; i++)
v = greylevels[*(pByte + i)]++; // access violation exception
}
Is it possible to do it? How could I do?
Thanks