How to split up an image?

I would like to cut an image into several parts, so I tried to use
wx.Image.Resize method. However, this method is not working as I would
expect. I tried to cut a smaller image from the center of a bigger
one, so I used something like:

# image size 300 x 300
image.Resize(size = (100,100), pos = (100, 100))

I tried negative coordinates, too, but the result is still weird and I
can't understand how Resize works. Could anyone explain it to me? Or
is there any better way to split up an image?

Thanks

Anna

Hi Anna.

For editing images with wxpython, I think the best way is to use a wx.DC object.

I’ve attached a small demonstration program that takes an image, and splits it into four separate images using wx.MemoryDC().

I’m not much of an expert on the subject, but hopefully this helps :).

Also check out the Python Image Library (PIL), it may be helpful.

Joseph.

splitup.zip (4.57 KB)

Oh, one thing I forgot in the code I attached is that at the end of the SplitUp() method I should have called dc.Clear()… Just to be safe.

Resize does exactly what it says, it resizes the image. To pull out a copy of the portion of an image you want to use the GetSubImage method.

···

On 10/2/11 1:01 AM, annakrat wrote:

I would like to cut an image into several parts, so I tried to use
wx.Image.Resize method. However, this method is not working as I would
expect. I tried to cut a smaller image from the center of a bigger
one, so I used something like:

# image size 300 x 300
image.Resize(size = (100,100), pos = (100, 100))

I tried negative coordinates, too, but the result is still weird and I
can't understand how Resize works. Could anyone explain it to me? Or
is there any better way to split up an image?

--
Robin Dunn
Software Craftsman

Thanks very much to both of you. I'm sorry I completely overlooked the
GetSubImage method.

Anna

···

On Oct 2, 9:39 pm, Robin Dunn <ro...@alldunn.com> wrote:

On 10/2/11 1:01 AM, annakrat wrote:

> I would like to cut an image into several parts, so I tried to use
> wx.Image.Resize method. However, this method is not working as I would
> expect. I tried to cut a smaller image from the center of a bigger
> one, so I used something like:

> # image size 300 x 300
> image.Resize(size = (100,100), pos = (100, 100))

> I tried negative coordinates, too, but the result is still weird and I
> can't understand how Resize works. Could anyone explain it to me? Or
> is there any better way to split up an image?

Resize does exactly what it says, it resizes the image. To pull out a
copy of the portion of an image you want to use the GetSubImage method.

--
Robin Dunn
Software Craftsmanhttp://wxPython.org