1
我得到一個「EXC_BAD_ACCESS」,但只是不能解決爲什麼,任何幫助將是巨大的 - 預先感謝您。NSThread共享對象問題
的用戶拍照時,我想要做一些處理就可以在另一個線程...
- (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();
}
它的形象,是給我所有的投訴...
我在做什麼錯?
很多感謝
在createThumbnailFromImage,不應圖像是inImage? – DyingCactus 2010-03-31 18:29:32