I wrote this Python Program to create and save a matrix (2D Array) to a .png file. The program compiles and runs without any error. Even the IMAGE.png file is created but the png file won't open. When I try to open it in MSPaint, it says:
Cannot open image. Not a valid bitmap file or its format is not currently supported.
My objective is to create a RBG png image based on the numbers stored in the 2D Array.
Source Code:
import numpy;
import png;
imagearray = numpy.zeros(shape=(512,512));
/* Code to insert one '1', '2', '3' in certain locations
of the numpy 2D Array. Rest of the location by default stores zero '0'.*/
f = open("IMAGE.png", 'wb');
f.write(imagearray);
f.close();
I don't understand where I went wrong as there is no error message. Please Help.
PS- I just want to save the matrix as an image file, so if you have a better and easy way of doing it in Python2.7, do suggest.