vtkPNGWriter to stream

Hi dear friends,

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

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 !

Something like this …

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 ?

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

which returns a unsigned char* to the element 0.