Problem for saving image to png

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

The code is:

			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

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

What’s the possible wrong with my code?

Is the file test.png generated?

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.

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/

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?