# Write a Scene to png

**URL:** https://discourse.vtk.org/t/write-a-scene-to-png/11392
**Category:** Support
**Created:** [May 6, 2023, 12:27am UTC](https://discourse.vtk.org/t/write-a-scene-to-png/11392 "2023-05-06T00:27:09Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Parisa\_Rabbani](https://discourse.vtk.org/user_avatar/discourse.vtk.org/parisa_rabbani/32/4295_2.png) [@Parisa\_Rabbani](https://discourse.vtk.org/u/Parisa_Rabbani)
#### Post date: [May 6, 2023, 12:27am UTC](https://discourse.vtk.org/t/write-a-scene-to-png/11392/1 "2023-05-06T00:27:09Z")

</div>

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:

 ![image](https://discourse.vtk.org/uploads/default/original/2X/7/782c7ea5184e0012893734d57f9e47dba80dd0ba.png)

Any help would be much appreciated.

Best,  
Parisa

---

<div class="post-metadata">

### Author: ![Jens\_Munk\_Hansen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jens_munk_hansen/32/1215_2.png) [@Jens\_Munk\_Hansen](https://discourse.vtk.org/u/Jens_Munk_Hansen)
#### Post date: [May 6, 2023, 5:50pm UTC](https://discourse.vtk.org/t/write-a-scene-to-png/11392/2 "2023-05-06T17:50:05Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Parisa\_Rabbani](https://discourse.vtk.org/user_avatar/discourse.vtk.org/parisa_rabbani/32/4295_2.png) [@Parisa\_Rabbani](https://discourse.vtk.org/u/Parisa_Rabbani)
#### Post date: [May 8, 2023, 4:00pm UTC](https://discourse.vtk.org/t/write-a-scene-to-png/11392/3 "2023-05-08T16:00:31Z")

</div>

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

 ![image](https://discourse.vtk.org/uploads/default/original/2X/0/0da881437f7c1c7c77648556e852b0bbb3650aa0.png)

Here’s the screenshot of the error:

 ![vtk_err](https://discourse.vtk.org/uploads/default/original/2X/e/edcb26cd794a3c6c47aab793c53b201fc85e4334.png)

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

 ![image](https://discourse.vtk.org/uploads/default/original/2X/8/87a488aed4ba6a43dc178b35fc160f502fc70655.png)

Any help would be much appreciated.

---

<div class="post-metadata">

### Author: ![Jens\_Munk\_Hansen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jens_munk_hansen/32/1215_2.png) [@Jens\_Munk\_Hansen](https://discourse.vtk.org/u/Jens_Munk_Hansen)
#### Post date: [May 9, 2023, 4:39pm UTC](https://discourse.vtk.org/t/write-a-scene-to-png/11392/4 "2023-05-09T16:39:23Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![geoffw](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/g/898d66/32.png) [@geoffw](https://discourse.vtk.org/u/geoffw)
#### Post date: [May 19, 2023, 4:17am UTC](https://discourse.vtk.org/t/write-a-scene-to-png/11392/5 "2023-05-19T04:17:18Z")

</div>

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);

```

…

---

<div class="post-metadata">

### Author: ![Parisa\_Rabbani](https://discourse.vtk.org/user_avatar/discourse.vtk.org/parisa_rabbani/32/4295_2.png) [@Parisa\_Rabbani](https://discourse.vtk.org/u/Parisa_Rabbani)
#### Post date: [May 19, 2023, 4:33pm UTC](https://discourse.vtk.org/t/write-a-scene-to-png/11392/6 "2023-05-19T16:33:12Z")

</div>

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.
