Python uses the PIL module to convert raw pictures into PNG pictures _python

Source: Internet
Author: User

This example describes how Python converts raw pictures into PNG pictures through the PIL module. Share to everyone for your reference. The specific analysis is as follows:

Python converts the raw picture into a PNG image through the PIL module, PIL contains the FromString function to read the picture information in the specified mode and save it.

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 bit data.
img = image.fromstring (' L ', imgsize, RawData, ' raw ', ' f;16 ')
img.save ("Foo.png")

Where the first parameter of the Image.fromstring function is specified as follows

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 no 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)

I hope this article will help you with your Python programming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.