PIL question

T

Thomas Heller

I'm trying to read an image with PIL, crop several subimages out of it,
and try to combine the subimages again into a combined new one. This is
a test script, later I want to only several single images into a combined one.

I have to work with 16-bit color windows bitmaps in BMP format.

My input image (input.bmp) IS a 16-color bmp. The cropped images that
the script saves are saved in 8-bit/256-color format; they look correct.
The combined image is also saved in 8-bit/256-color format, but it is
all black - maybe the palette is missing?

Anyway, I cannot use 256-color images. How do I save the images in 4-bit/16-color
format?

Thanks,
Thomas

Here is the code; I'm using Python 2.4 and PIL 1.5:

<code>
import Image
img = Image.open("input.bmp")

w, h = img.size
print img.size, img.mode

newimg = Image.new("P", (16*30, 15))

x = 0
i = 1
while x < w:
this = img.crop((x, 0, x+16, 15))
this.save("%02d.bmp" % i)
newimg.paste(this, (x, 0, x+16, 15))
x += 16
i += 1

newimg.save("output.bmp")

<code/>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top