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.