imwrite

imwrite(X,file) creates a PNG image from matrix X where each point in X defines the RGB identifier for each pixel. The second intput argument defines the target file name.

The RGB identifiers used in matrix X must be consistent with the ones used in VBA, ie for pixel i-th row, j-th column, the following conversions are applied to get the final RGB values to be used for the PNG file:
rem(X(i,j), 256) defines PNG red
rem(floor(X(i,j) / 256), 256) defines PNG green
rem(floor(X(i,j) / 65536), 256) defines PNG blue

See also

imread