擅长:python、mysql、java
<p>我应该创建一个2D数组,每一行都是<code>3*width</code>,并且包含连续的RGB值</p>
<pre><code>pngFile1 = png.Reader("file1.png").read()
pngFile2 = png.Reader("file2.png").read()
pngFile3 = png.Reader("file3.png").read()
pngArray1 = np.array(list(pngFile1[2]))
pngArray2 = np.array(list(pngFile2[2]))
pngArray3 = np.array(list(pngFile3[2]))
//get dimension, assuming they are the same for all three images
width = pngArray1[0]
height = pngArray1[1]
//create a 2D array to use on the png.Writer
pngArray = np.zeros([height, 3*width])
for i in range(height)
for j in range(width)
pngArray[i][j*3 + 0] = pngArray1[i][j]
pngArray[i][j*3 + 1] = pngArray2[i][j]
pngArray[i][j*3 + 2] = pngArray3[i][j]
fileStream = open("pngFileRGB.png", "wb")
writer = png.Writer(width, height)
writer.write(fileStream, pngArray)
fileStream.close()
</code></pre>