# vtkPNGWriter to stream

**URL:** https://discourse.vtk.org/t/vtkpngwriter-to-stream/7029
**Category:** Support
**Created:** [November 1, 2021, 11:08am UTC](https://discourse.vtk.org/t/vtkpngwriter-to-stream/7029 "2021-11-01T11:08:49Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Olivier](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/o/d2c977/32.png) [@Olivier](https://discourse.vtk.org/u/Olivier)
#### Post date: [November 1, 2021, 11:08am UTC](https://discourse.vtk.org/t/vtkpngwriter-to-stream/7029/1 "2021-11-01T11:08:49Z")

</div>

Hi dear friends,

I want to make a screenshot of a VTK Renderer into a PNG stream.  
Way to go is obviously

```auto
vtkNew<vtkRenderLargeImage> renderLarge;
renderLarge->SetInput(renderer);

vtkNew<vtkPNGWriter> writer;
writer->SetInputConnection(renderLarge->GetOutputPort());
writer->WriteToMemoryOn();
writer->Write();
auto png = writer->GetResult();

```

but I don’t know how to translate the resulting “vtkUnsignedCharArray” into a contiguous “unsigned char\*” to pass back to the caller …

Any advice ?  
Thanks !

---

<div class="post-metadata">

### Author: ![Olivier](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/o/d2c977/32.png) [@Olivier](https://discourse.vtk.org/u/Olivier)
#### Post date: [November 1, 2021, 11:23am UTC](https://discourse.vtk.org/t/vtkpngwriter-to-stream/7029/2 "2021-11-01T11:23:59Z")

</div>

Something like this …

```auto
auto data = new unsigned char[png->GetSize()];
for (int i=0; i<data->Length; i++) data[i] = png->GetValue(i);

```

Nothing more efficient involving direct memory data copy ?

---

<div class="post-metadata">

### Author: ![danlipsa](https://discourse.vtk.org/user_avatar/discourse.vtk.org/danlipsa/32/390_2.png) [@danlipsa](https://discourse.vtk.org/u/danlipsa)
#### Post date: [November 1, 2021, 3:35pm UTC](https://discourse.vtk.org/t/vtkpngwriter-to-stream/7029/3 "2021-11-01T15:35:30Z")

</div>

You can get access to the pointer to the actual data using:  
GetPointer(0)

which returns a unsigned char\* to the element 0.
