python通过pil模块将raw图片转换成png图片的方法

yipeiwu_com5年前Python基础

本文实例讲述了python通过pil模块将raw图片转换成png图片的方法。分享给大家供大家参考。具体分析如下:

python通过pil模块将raw图片转换成png图片,pil中包含了fromstring函数可以按照指定模式读取图片信息然后进行保存。

rawData = open("foo.raw" 'rb').read()
imgSize = (x,y)
# 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.fromstring('L', imgSize, rawData, 'raw', 'F;16')
img.save("foo.png")

其中Image.fromstring函数的第一个参数具体含义如下

1 (1-bit pixels, black and white, stored with one pixel per byte)
L (8-bit pixels, black and white)
P (8-bit pixels, mapped to any other mode using a colour palette)
RGB (3x8-bit pixels, true colour)
RGBA (4x8-bit pixels, true colour with transparency mask)
CMYK (4x8-bit pixels, colour separation)
YCbCr (3x8-bit pixels, colour video format)
I (32-bit signed integer pixels)
F (32-bit floating point pixels)

希望本文所述对大家的Python程序设计有所帮助。

相关文章

python实现mysql的读写分离及负载均衡

python实现mysql的读写分离及负载均衡

Oracle数据库有其公司开发的配套rac来实现负载均衡,目前已知的最大节点数能到128个,但是其带来的维护成本无疑是很高的,并且rac的稳定性也并不是特别理想,尤其是节点很多的时候。...

Python实现在线暴力破解邮箱账号密码功能示例【测试可用】

本文实例讲述了Python实现在线暴力破解邮箱账号密码功能。分享给大家供大家参考,具体如下: dic 字典格式如下(mail.txt) : username@gmail.com:pa...

pyqt5对用qt designer设计的窗体实现弹出子窗口的示例

1. 用qt designer编写主窗体,窗体类型是MainWindow,空白窗口上一个按钮。并转换成mainWindow.py # -*- coding: utf-8 -*- #...

分享vim python缩进等一些配置

VIM python下的一些关于缩进的设置: 第一步: 打开终端,在终端上输入vim ~/.vimrc,回车。 第二步: 添加下面的文段: set filetype=p...

对numpy中的transpose和swapaxes函数详解

transpose() 这个函数如果括号内不带参数,就相当于转置,和.T效果一样,而今天主要来讲解其带参数。 我们看如下一个numpy的数组: `arr=np.arange(16)...