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

yipeiwu_com6年前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之自动获取公网IP的实例讲解

Python之自动获取公网IP的实例讲解

0.预备知识 0.1 SQL基础 ubuntu、Debian系列安装: root@raspberrypi:~/python-script# apt-get install mysql...

Python3进制之间的转换代码实例

Python3进制之间的转换 在Python里面实现进制之间的转换是非常方便的,有专门的函数来进行这个操作: 下面直接上代码: # 进制之间的转换 a = 10 # 转换为二进制...

在django view中给form传入参数的例子

在django的form表单会出现,在form的验证或者保存时需要非form中的field的信息参数。例如在对操作进行记录,我们需要根据将记录的操作人设置为当前的用户,所以在view中我...

python命令行参数sys.argv使用示例

复制代码 代码如下:#diff.py#!/bin/env python import sys if len(sys.argv) <> 3:   ...

Python-Seaborn热图绘制的实现方法

Python-Seaborn热图绘制的实现方法

制图环境: pycharm python-3.6 Seaborn-0.8 热图 import numpy as np import seaborn as sns import...