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实现嵌套列表去重方法示例

发现问题 python嵌套列表大家应该都不陌生,但最近遇到了一个问题,这是工作中遇到的一个坑,首先看一下问题 raw_list = [["百度", "CPY"], ["京东", "C...

Python实现的简单排列组合算法示例

本文实例讲述了Python实现的简单排列组合算法。分享给大家供大家参考,具体如下: 1.python语言简单、方便,其内部可以快速实现排列组合算法,下面做简单介绍 2.一个列表数据任意组...

Python基础学习之时间转换函数用法详解

Python基础学习之时间转换函数用法详解

本文实例讲述了Python基础学习之时间转换函数用法。分享给大家供大家参考,具体如下: 前言 python的时间格式分为多种,几种格式之间的转换方法时常是我们遇到的而且是经常忘记的点,p...

解决Python命令行下退格,删除,方向键乱码(亲测有效)

一、出现原因:readline模块没有安装 二、解决方式: # 安装readline模块 yum -y install readline-devel # 进入Python安装目录 c...

Django 全局的static和templates的使用详解

Django 全局的static和templates的使用详解

一、问题 首先我们在进行Django框架搭建的时候我们需要建立一个全局的变量,一是为了实现代码的复用,二是为了方便管理,如下图的样式 二、解决 1、修改setting里面的配置文件...