...
ASICameraDll2.ASIGetROIFormat(CameraID, out width, out height, out bin, out ImageType);
IntPtr ImageBuf;//== IntPtr.Zero
int size = width * height;
if (ImageType == ASICameraDll2.ASI_IMG_TYPE.ASI_IMG_RAW16)
size *= 2;
ImageBuf = Marshal.AllocCoTaskMem(size);
if (ASICameraDll2.ASIGetVideoData(CameraID, ImageBuf, size, 0) == ASICameraDll2.ASI_ERROR_CODE.ASI_SUCCESS)
{
byte dataByte=null;
if (ImageType == ASICameraDll2.ASI_IMG_TYPE.ASI_IMG_RAW16)
size *= 2;
dataByte = new byte;
Marshal.Copy(ImageBuf, dataByte, 0, size);
...
}
...
Marshal.FreeCoTaskMem(ImageBuf);