raw格式的圖像轉爲可以查看的png格式

將raw格式的圖像轉爲可以查看的png格式:

# coding:utf-8
from PIL import ImagerawData = open('Color_74.raw','rb').read()
imgSize = (640,480) ###The size of the image
# Use the PIL raw decoder to read the data.
# the 'F;16' informs the raw decoder that we are reading
# a little endian, unsigned integer 16 bit data.
img = Image.frombytes('RGB', imgSize, rawData, 'raw')
img.save("foo.png")

需要預先知道圖像的尺寸,還有圖像的格式,是RGB還是灰度圖像等。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章