I'm using a C++/CLI wrapper to call a c++ library from c# .NET. While this particular code "works," I suspect that I'm doing something wrong with respect to memory. (I run into problems after running this code about 20 times in a row.)
c# side:
public void ExportModelToImage(int[] myImage, int imageWidth, int imageHeight)
{
View.ExportModelToImage(ref myImage, imageWidth, imageHeight);
}
C++/CLI side:
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;
}
}
}
Ideally, I would prefer if ExportModelToImage() returned an int array instead of returning by reference, but I've had problems figuring out the correct way to do that in C++/CLI. Any suggestions would be greatly appreciated. Thanks!