# How to use Png Reader to geneate ImageData

**URL:** https://discourse.vtk.org/t/how-to-use-png-reader-to-geneate-imagedata/3493
**Category:** Support
**Created:** [June 8, 2020, 7:25pm UTC](https://discourse.vtk.org/t/how-to-use-png-reader-to-geneate-imagedata/3493 "2020-06-08T19:25:15Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![beginner](https://discourse.vtk.org/user_avatar/discourse.vtk.org/beginner/32/1930_2.png) [@beginner](https://discourse.vtk.org/u/beginner)
#### Post date: [June 8, 2020, 7:25pm UTC](https://discourse.vtk.org/t/how-to-use-png-reader-to-geneate-imagedata/3493/1 "2020-06-08T19:25:15Z")

</div>

Hi. I am new to VTK and I am wondering as to how I can generate Image Data after using png reader. Any form of help would be appreciated. Thanks!

---

<div class="post-metadata">

### Author: ![scotsman60](https://discourse.vtk.org/user_avatar/discourse.vtk.org/scotsman60/32/6000_2.png) [@scotsman60](https://discourse.vtk.org/u/scotsman60)
#### Post date: [June 9, 2020, 6:22am UTC](https://discourse.vtk.org/t/how-to-use-png-reader-to-geneate-imagedata/3493/2 "2020-06-09T06:22:10Z")

</div>

There’s an example for this here :[https://lorensen.github.io/VTKExamples/site/Cxx/IO/PNGReader/](https://lorensen.github.io/VTKExamples/site/Cxx/IO/PNGReader/)

This example sets up a pipeline to read the file and pass the output directly to a viewer. If you need to get the actual vtkImageData you can extract it as follows (I work mostly in Python so the following C++ may not be correct…)

```
// This is from the exmple
vtkSmartPointer<vtkPNGReader> reader =
vtkSmartPointer<vtkPNGReader>::New();
reader->SetFileName(argv[1]); 

reader->Update()
vtkSmartPointer<vtkImageData> imageData;

imageData = reader->GetOutput()
```
