我得到了一个“EXC_BAD_ACCESS”,但是无法解决原因,任何帮助都会很大 - 请提前谢谢。
用户拍照,我想在另一个线程中对其进行一些处理...
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
...
NSString *uid = [Asset stringWithUUID];
[_imageQueue setObject:img forKey:uid];
[NSThread detachNewThreadSelector:@selector(createAssetAsyncWithImage:)
toTarget:self
withObject:uid];
}
然后是新线程
-(void) createAssetAsyncWithImage:(NSString *)uid {
NSAutoreleasePool * pool =[[NSAutoreleasePool alloc] init];
if ([_imageQueue objectForKey:uid]) {
Asset *asset = [Asset createAssetWithImage:[_imageQueue objectForKey:uid]];
asset.uid = uid;
[self performSelectorOnMainThread:@selector(asyncAssetCreated:)
withObject:asset
waitUntilDone:YES];
}
[pool release];
}
哪个电话
+(Asset *)createAssetWithImage:(UIImage *)img
{
....
UIImage *masterImg = [GraphicSupport createThumbnailFromImage:img pixels:img.size.height/2];
....
return newAsset;
}
然后这就是我继续获得BAD_ACCESS
的地方+(UIImage *)createThumbnailFromImage:(UIImage *)inImage pixels:(float)pixels{
CGSize size = image.size;
CGFloat ratio = 0;
if (size.width > size.height) {
ratio = pixels / size.width;
}
else {
ratio = pixels / size.height;
}
CGRect rect = CGRectMake(0.0, 0.0, ratio * size.width, ratio * size.height);
UIGraphicsBeginImageContext(rect.size);
//NSAssert(image,@"image NULL");
[image drawInRect:rect];
return UIGraphicsGetImageFromCurrentImageContext();
}
这是给我所有投诉的形象......
我做错了什么?
非常感谢提前
答案 0 :(得分:0)
我发现UIGraphicsBeginImageContext不是多线程的,不得不求助于Trevors fab扩展到UIImage。
http://vocaro.com/trevor/blog/2009/10/12/resize-a-uiimage-the-right-way/