- What could cause [UIImage imageWithData] to crash when it comes back
- if (self.tempImageStorage) {
- return self.tempImageStorage;
- } else if(self.imageData) {
- NSLog(@"%@ %d",self.imageData, self.imageData.length);
- self.tempImageStorage = [UIImage imageWithData:self.imageData];
- return self.tempImageStorage;
- }
- - (void) processRequest:(ASIHTTPRequest *) request
- {
- UIImage * orig = [UIImage imageWithData:[request responseData]];
- CGSize targetSize = isPad()?CGSizeMake(446,150):CGSizeMake(320, 108);
- CGRect fourPanelSize = CGRectMake(0, 0, 1000, 336);
- CGImageRef imageRef = CGImageCreateWithImageInRect([orig CGImage], fourPanelSize);
- CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(imageRef);
- CGColorSpaceRef colorSpaceInfo = CGImageGetColorSpace(imageRef);
- if (bitmapInfo == kCGImageAlphaNone || bitmapInfo == kCGImageAlphaLast) {
- bitmapInfo = kCGImageAlphaPremultipliedLast;
- }
- CGContextRef bitmap;
- bitmap = CGBitmapContextCreate(NULL, targetSize.width, targetSize.height, CGImageGetBitsPerComponent(imageRef), CGImageGetBytesPerRow(imageRef), colorSpaceInfo, bitmapInfo);
- CGContextDrawImage(bitmap, CGRectMake(1, 1, targetSize.width-2, targetSize.height-2), imageRef);
- CGImageRef ref = CGBitmapContextCreateImage(bitmap);
- UIImage* newImage = [UIImage imageWithCGImage:ref];
- CGContextRelease(bitmap);
- CGImageRelease(ref);
- NSData * thumbData = UIImagePNGRepresentation(newImage);
- NSData * imageData = UIImagePNGRepresentation(orig);
- //Post notification on main thread since it will be updating the UI
- [[NSOperationQueue mainQueue] addOperationWithBlock:^{
- self.tempImageThumbStorage = newImage;
- self.imageThumbnailData = thumbData;
- self.tempImageStorage = orig;
- self.imageData = imageData;
- [(AppDelegate*)[UIApplication sharedApplication].delegate saveContext];
- NSMutableDictionary * userInfo = [[NSMutableDictionary alloc] initWithCapacity:1];
- [userInfo setObject:[NSNumber numberWithBool:YES] forKey:@"status"];
- [userInfo setObject:self forKey:@"comic"];
- [[NSNotificationCenter defaultCenter] postNotificationName:PCRLoadMediahNotification object:self userInfo:userInfo];
- strongSelf = nil;
- }];
- }