Tengo un hilo de fondo que carga imágenes y las muestra en el hilo principal. Me di cuenta de que el subproceso de fondo tiene casi nada que hacer, ya que la decodificación de imagen real parece estar hecho en el hilo principal:Decodifica imágenes en el hilo de fondo?
Hasta ahora he intentado llamar [UIImage imageNamed:]
, [UIImage imageWithData:]
y CGImageCreateWithJPEGDataProvider
en el fondo hilo sin diferencia ¿Hay alguna manera de forzar la decodificación en el hilo de fondo?
Ya hay a similar question aquí, pero no ayuda. Como he escrito allí, probé el siguiente truco:
@implementation UIImage (Loading)
- (void) forceLoad
{
const CGImageRef cgImage = [self CGImage];
const int width = CGImageGetWidth(cgImage);
const int height = CGImageGetHeight(cgImage);
const CGColorSpaceRef colorspace = CGImageGetColorSpace(cgImage);
const CGContextRef context = CGBitmapContextCreate(
NULL, /* Where to store the data. NULL = don’t care */
width, height, /* width & height */
8, width * 4, /* bits per component, bytes per row */
colorspace, kCGImageAlphaNoneSkipFirst);
NSParameterAssert(context);
CGContextDrawImage(context, CGRectMake(0, 0, width, height), cgImage);
CGContextRelease(context);
}
@end
que funciona (obliga a la imagen para decodificar), pero también desencadena una llamada al parecer costoso ImageIO_BGR_A_TO_RGB_A_8Bit
.
gracias, funciona genial. – Morrowless