我使用的是C ++ / CLI包装调用从C#.NET中的一个C ++库。 虽然这个特殊的代码“的作品,”我怀疑我做错了关于内存。 (我碰上连续运行此代码约20倍后的问题。)
C#的一面:
public void ExportModelToImage(int[] myImage, int imageWidth, int imageHeight)
{
View.ExportModelToImage(ref myImage, imageWidth, imageHeight);
}
C ++ / CLI侧:
void ExportModelToImage(array<int>^% myImage, int imageWidth, int imageHeight)
{
if (myView().IsNull())
{
return;
}
myView()->Redraw();
Image_PixMap theImage;
myView()->ToPixMap(theImage, imageWidth, imageHeight);
const int totalBytes = imageWidth * imageHeight;
int byteIndex = 0;
Standard_Integer si = 0;
Quantity_Color aColor;
Quantity_Parameter aDummy;
for (Standard_Size aRow = 0; aRow < theImage.SizeY(); ++aRow)
{
for (Standard_Size aCol = 0; aCol < theImage.SizeX(); ++aCol)
{
aColor = theImage.PixelColor((Standard_Integer )aCol, (Standard_Integer )aRow, aDummy);
aColor.Color2argb(aColor, si);
myImage[byteIndex] = (int) si;
byteIndex++;
if (byteIndex > totalBytes) return;
}
}
}
理想情况下,如果ExportModelToImage()返回而不是通过引用返回一个int数组我愿意,但我有问题,找出正确的方法做,在C ++ / CLI。 任何建议将不胜感激。 谢谢!