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之消除前缀重命名的方法

● 脚本用途 遍历文件夹下的文件,消除文件名前的特征字符串。 ● 脚本实现 import os,sys import re from string import Template...

python中类的属性和方法介绍

Python-类属性,实例属性,类方法,静态方法,实例方法 类属性和实例属性 #coding:utf-8 class Student(object): name = 'I am...

Python实现基于KNN算法的笔迹识别功能详解

Python实现基于KNN算法的笔迹识别功能详解

本文实例讲述了Python实现基于KNN算法的笔迹识别功能。分享给大家供大家参考,具体如下: 需要用到: Numpy库 Pandas库 手写识别数据 点击此处本站下载。...

Python的iOS自动化打包实例代码

Python的iOS自动化打包实例代码

前言 这段时间刚刚学习了一段时间的Python,加上自己是做iOS开发的,就想着用Python来做一个自动化打包,可以自动完成打包,上传到蒲公英,并且发送邮箱给测试人员. 一是可以减...

PyTorch的深度学习入门教程之构建神经网络

前言 本文参考PyTorch官网的教程,分为五个基本模块来介绍PyTorch。为了避免文章过长,这五个模块分别在五篇博文中介绍。 Part3:使用PyTorch构建一个神经网络 神经网络...