tags:

views:

41

answers:

2

Is that possible to read just a small rectangle area of a large image file?

A: 

Try: CGImageCreateWithImageInRect

TSG
Thanks but I think this method is for copying part of an image to another. This is not what I need. I need to read from the image file, just the bytes correspondent to a given rect area.
Digital Robot
+3  A: 

This is not possible. First of all the iPhone api certainly doesn't support it. More importantly, image formats such as JPEG generally store the pixels row by row, and then apply sequential compression to the entire stream - that means you must start at the beginning and follow through. (not sure about PNG)

Your best bet, if you need this really bad, for jpeg, is to link against a clone of libjpeg in which you hack some stuff to skip through the Huffman(-ish) encoded 8x8 MCU blocks, and only store the part you need.

From experience I can tell that the speed gain will be some 70% if you apply a truckload of tricks to skip from one MCU block to the next, without actually decoding them. (I needed only the very first entry of each block for a fast 8-to-1 downscaling)

It would be a very interesting project, but unless you feel a pressing need I would just read in the entire image and then slice out the part you need.

mvds
ps. I looked it up, decoding in libjpeg revolves around `decode_mcu()` in `jdhuff.c`
mvds
thanks. This is exactly what I need. I will research if it is viable to continue on this approach... thanks.
Digital Robot