469,358 Members | 1,651 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,358 developers. It's quick & easy.

PIL question

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/>

Nov 16 '07 #1
0 1058

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Mohammed Mazid | last post: by
3 posts views Thread by Stevey | last post: by
10 posts views Thread by glenn | last post: by
53 posts views Thread by Jeff | last post: by
56 posts views Thread by spibou | last post: by
2 posts views Thread by Allan Ebdrup | last post: by
3 posts views Thread by Zhang Weiwu | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.