ios解码图像的一部分

Aka*_*sQc 9 core-graphics objective-c ios

我有一个太大的图像,无法加载到内存中,但我只对该大图像中的一组子像素感兴趣.是否有可能只将这个像素子集解码到内存中?我知道在Android中有一个类正在做这个叫做BitmapRegionDecoder的类就是这样的

我找到了CGDataProviderCreateSequential,但它需要构造函数中的原始像素...

现在我正在做这样的事情:

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);
Run Code Online (Sandbox Code Playgroud)

Dav*_*d H 10

唯一可行的方法是创建一个CGImageSourceCreateWithData()(或URL),然后创建一个CGImageRef使用CGImageCreateWithJPEGDataProviderCGImageCreateWithPNGDataProvider.有了它CGImageRef,你可以尝试使用CGImageCreateWithImageInRect()并拉出大图像的一个子部分.

如果您要做的是平铺图像,请澄清您的问题,因为我会为您提供更多信息.