1
讓我們考慮的例子:如何在ASCII模式下讀取pbm文件的大小?
的PBM文件「imFile.pbm」中包含的像素如下:
P1
# Comment
9 6
0 0 0 0 0 0 0 0 0
0 1 1 0 0 0 0 0 0
0 1 1 0 0 0 0 0 0
0 1 1 0 0 0 0 0 0
0 1 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
如何確定圖像的寬度和高度。我已經使用了下面的代碼,但失敗了。
with open("imFile.pbm", 'rb') as f:
image = f.size
print image
f.close()
當我編譯它在我的ubuntu14.04操作系統,它顯示錯誤。任何建議將不勝感激。先謝謝你。
的寬度和高度,就在那裏的文件中,第一行中的第一個之後,跳過評論。這不是'.size'的用途;你需要閱讀和解析文件。 – Amadan
@ Amadan--我該怎麼做?你能解釋我的話嗎? –