Есть ли способ создать объект UIImage из неэкранной поверхности без копирования данных основного пикселя?
Я бы хотел сделать что-то вроде этого:
// These numbers are made up obviously...
CGContextRef offscreenContext = MyCreateBitmapContext(width, height);
// Draw into the offscreen buffer
// Draw commands not relevant...
// Convert offscreen into CGImage
// This consumes ~15MB
CGImageRef offscreenContextImage = CGBitmapContextCreateImage(offscreenContext);
// This allocates another ~15MB
// Is there any way to share the bits from the
// CGImageRef instead of copying the data???
UIImage * newImage = [[UIImage alloc] initWithCGImage:offscreenContextImage];
// Releases the original 15MB, but the spike of 30MB total kills the app.
CGImageRelease(offscreenContextImage);
CGContextRelease(offscreenContext);
Память высвобождается и выравнивается до приемлемого размера, но всплеск памяти в 30 МБ убивает приложение. Есть ли способ поделиться данными пикселей?
Я подумал о том, чтобы сохранить внеэкранный буфер в файл и снова загрузить данные, но это взлом, и для удобства iPhone требуются UIImage для его сохранения ...