using System.Runtime.InteropServices;
using Cognex.VisionPro;
public static ICogImage ConvertImage(byte[] bytes, int width, int height)
{
if (bytes == null || bytes.Length == 0)
return null;
if (width == 0 || height == 0)
return null;
try
{
IntPtr ptr = Marshal.UnsafeAddrOfPinnedArrayElement(bytes, 0);
CogImage8Root rt = new CogImage8Root();
rt.Initialize(width, height, ptr, width, null);
CogImage8Grey outputImg = new CogImage8Grey();
outputImg.SetRoot(rt);
return outputImg;
}
catch (Exception x)
{
}
return null;
}
} |