Write a Scene to png

Hi!

I have a vtkchart plot, I am trying to write my plot as png. It seems like “vtkWindowToImageFilter” has some issue. I get the following error:

Any help would be much appreciated.

Best,
Parisa

Difficult to see from a screenshot without context. I can see on the image that you assign both input data and an input connection to a writer. That is not right

I removed the image data assignment to the writer. I still have the issue. Please see part of the code that crashed below:

Here’s the screenshot of the error:

This is the plot I am trying to write as png, (window size: (1000,1000))

Any help would be much appreciated.

I believe you need to render the window after you have configured the filter to work on its output. The vtkWindowToImageFilter you assign an input not a connection.

You could try pulling the data out manually and see what you get. We do something like this by starting with this:

vtkImageData *imageData = windowToImageFilter->GetOutput();
int dims[3] = {0};
imageData->GetDimensions(dims);

int tnSize = dims[0] * dims[1] * 4;
uchar *rgba = (uchar *)imageData->GetScalarPointer();

std::vector<uchar> rgb(rgba, rgba + tnSize);

Thank you Geoff.
The issue got solved. I found out I had mismatched debug and release libraries. So I changed all to debug and the writing issue got fixed.
I faced another problem after this, I couldn’t add labels to x or y axis in debug mode.
Which till this day I am not sure why, but using cmake for linking and initializing fixed that as well. I am guessing I should have used autoinit for something but anyways cmake fixed it.