ios Decode part of an image

core-graphics, ios, objective-c

Solution

The only possible way this might work is if you create an `CGImageSourceCreateWithData()` (or URL whatever), then create a `CGImageRef` using `CGImageCreateWithJPEGDataProvider` or `CGImageCreateWithPNGDataProvider`. With that `CGImageRef`, you could TRY to use `CGImageCreateWithImageInRect()` and pull a subsection of the big image out.

If what you are trying to do is tile the image please clarify your question as I would have more information for you then.

Problem

I have a big image which is too big to be loaded into memory but i am only interested in a sub set of pixels within that big image. Is it possible to decode into memory only this subset of pixels? I know that in Android there is a class in the API to do exactly this called BitmapRegionDecoder are something like that I found CGDataProviderCreateSequential but it needs the raw pixels in the constructor... Right now i am doing something like this : ``` UIImage* srcImage = ...; CFDataRef cgImgDataRef = CGDataProviderCopyData(CGImageGetDataProvider(srcImage.CGImage));//After this call, all pixels are decoded into memory and the app crashes char* imageData = (char*)CFDataGetBytePtr(cgImgDataRef); ```

Original source