我使用下面的代码在后台线程中创建一个UIImage,然后将此图像设置为主线程上我的视图的图像。偶尔,我得到一个糟糕的访问错误。我想知道我是否应该在后台线程中创建UIImage。有什么想法吗?
CGImageRef imageRef =
CGImageCreate(serverInit.rfbWidth,serverInit.rfbHeight,bitsPerComponent,bitsPerPixel,bytesPerRow,colorSpaceRef,bitmapInfo,provider,NULL,NO,renderingIntent);
screenImage = [UIImage imageWithCGImage:imageRef];
CFRelease(imageRef);
[view performSelector:@selector(replaceImage:) onThread:[NSThread mainThread] withObject:screenImage waitUntilDone:NO];
答案 0 :(得分:0)
尝试使用它,它可以防止发布screenImage
CGImageRef imageRef = CGImageCreate(serverInit.rfbWidth,serverInit.rfbHeight,bitsPerComponent,bitsPerPixel,bytesPerRow,colorSpaceRef,bitmapInfo,provider,NULL,NO,renderingIntent);
screenImage = [UIImage imageWithCGImage:imageRef];
CFRelease(imageRef);
dispatch_sync(dispatch_get_main_queue(), ^{
[view replaceImage:screenImage];
});