PIL library 直接對pixel運算

看板Python作者 (Ar藤)時間16年前 (2008/11/29 21:41), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串1/1
我想將一張bmp圖的各個顏色 做亂數轉換 google得知PIL是強大的影像處理library 不過我查不到怎麼直接對點做控制 下面是直接硬上寫出來的 沒用PIL 不知是否有版友用過PIL寫過類似的東西 可否貼個例子參考一下@@a =========================================================== def byteToInt(data): sum=0 k=0 for i in data: sum+=ord(i)*pow(2,k) k+=8 return sum from random import * openFile=open("pic.bmp","rb") BMPData=openFile.read() openFile.seek(10) #點陣圖資料開始之前的偏移量(單位:byte) bmpPointOffset=byteToInt(openFile.read(4)) #點陣圖資料開始之前的偏移量(單位: byte) for count in range(5): writeFile=open("change"+str(count)+".bmp",'wb') permutationList=range(256) shuffle(permutationList) permutationList=[chr(i) for i in permutationList] for i in BMPData[0:bmpPointOffset]: #寫進一樣的header writeFile.write(i) for i in BMPData[bmpPointOffset:]: j=permutationList[byteToInt(i)] writeFile.write(j) writeFile.close() openFile.close() -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.114.229.83

11/29 22:39, , 1F
im.getpixel(xy) 之類的很多, 把manual翻過一遍吧
11/29 22:39, 1F
文章代碼(AID): #19CKQb6B (Python)
文章代碼(AID): #19CKQb6B (Python)