# Problem for saving image to png

**URL:** https://discourse.vtk.org/t/problem-for-saving-image-to-png/2924
**Category:** Support
**Created:** [March 31, 2020, 9:57am UTC](https://discourse.vtk.org/t/problem-for-saving-image-to-png/2924 "2020-03-31T09:57:47Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![NeuZhangQiang](https://discourse.vtk.org/user_avatar/discourse.vtk.org/neuzhangqiang/32/2248_2.png) [@NeuZhangQiang](https://discourse.vtk.org/u/NeuZhangQiang)
#### Post date: [March 31, 2020, 9:57am UTC](https://discourse.vtk.org/t/problem-for-saving-image-to-png/2924/1 "2020-03-31T09:57:48Z")

</div>

I want to save a image to png, and it is OK. However, when I read it, bug happens.

The code is:

```auto
			vtkSmartPointer<vtkPNGWriter> imgWriter = vtkSmartPointer<vtkPNGWriter>::New();
			imgWriter->SetInputData(img);
			imgWriter->SetFileName("test.png");
			imgWriter->Update();

			vtkSmartPointer<vtkPNGReader> imgReader = vtkSmartPointer<vtkPNGReader>::New();
			imgReader->SetFileName("test.png");
			imgReader->Update();

```

It is OK for imgWriter-\>Update(), but for imgReader-\>Update(), a bug is reported as

```auto
vtkPNGReader (00000146604DD6E0): Unknown file type! Not a PNG file!

```

What’s the possible wrong with my code?

---

<div class="post-metadata">

### Author: ![GonzaloS](https://discourse.vtk.org/user_avatar/discourse.vtk.org/gonzalos/32/926_2.png) [@GonzaloS](https://discourse.vtk.org/u/GonzaloS)
#### Post date: [March 31, 2020, 11:05am UTC](https://discourse.vtk.org/t/problem-for-saving-image-to-png/2924/2 "2020-03-31T11:05:02Z")

</div>

Is the file test.png generated?

---

<div class="post-metadata">

### Author: ![NeuZhangQiang](https://discourse.vtk.org/user_avatar/discourse.vtk.org/neuzhangqiang/32/2248_2.png) [@NeuZhangQiang](https://discourse.vtk.org/u/NeuZhangQiang)
#### Post date: [April 1, 2020, 1:32am UTC](https://discourse.vtk.org/t/problem-for-saving-image-to-png/2924/3 "2020-04-01T01:32:54Z")

</div>

Yes, the test.png is generated. But I can not open the test.png in my computer (win10).

I have tried the png, jpg writer and reader, and the writer is OK but reader is failed. Then, I test the bmp writer, and the bmp writer and reader is OK. I am very confuzed about the png and jpg writer and reader.

---

<div class="post-metadata">

### Author: ![andreasbuykx](https://discourse.vtk.org/user_avatar/discourse.vtk.org/andreasbuykx/32/8137_2.png) [@andreasbuykx](https://discourse.vtk.org/u/andreasbuykx)
#### Post date: [April 1, 2020, 4:59am UTC](https://discourse.vtk.org/t/problem-for-saving-image-to-png/2924/4 "2020-04-01T04:59:01Z")

</div>

With image writers you should call `Write`, not `Update`.  
You can find some examples like this [https://lorensen.github.io/VTKExamples/site/Java/Utilities/Screenshot/](https://lorensen.github.io/VTKExamples/site/Java/Utilities/Screenshot/)

---

<div class="post-metadata">

### Author: ![NeuZhangQiang](https://discourse.vtk.org/user_avatar/discourse.vtk.org/neuzhangqiang/32/2248_2.png) [@NeuZhangQiang](https://discourse.vtk.org/u/NeuZhangQiang)
#### Post date: [April 1, 2020, 10:04am UTC](https://discourse.vtk.org/t/problem-for-saving-image-to-png/2924/5 "2020-04-01T10:04:59Z")

</div>

Thank you very much. But jpg, png and bmp only accept unsigned char input. what if I want to save float image in the disk?
