Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 9th, 2012  |  syntax: None  |  size: 2.25 KB  |  hits: 25  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. What could cause [UIImage imageWithData] to crash when it comes back
  2. if (self.tempImageStorage) {
  3.     return self.tempImageStorage;
  4. } else if(self.imageData) {
  5.     NSLog(@"%@ %d",self.imageData, self.imageData.length);
  6.     self.tempImageStorage = [UIImage imageWithData:self.imageData];
  7.     return self.tempImageStorage;
  8. }
  9.        
  10. - (void) processRequest:(ASIHTTPRequest *) request
  11. {
  12.     UIImage * orig = [UIImage imageWithData:[request responseData]];
  13.     CGSize targetSize = isPad()?CGSizeMake(446,150):CGSizeMake(320, 108);
  14.     CGRect fourPanelSize = CGRectMake(0, 0, 1000, 336);
  15.     CGImageRef imageRef = CGImageCreateWithImageInRect([orig CGImage], fourPanelSize);
  16.     CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(imageRef);
  17.     CGColorSpaceRef colorSpaceInfo = CGImageGetColorSpace(imageRef);
  18.  
  19.     if (bitmapInfo == kCGImageAlphaNone || bitmapInfo == kCGImageAlphaLast) {
  20.         bitmapInfo = kCGImageAlphaPremultipliedLast;
  21.     }
  22.  
  23.     CGContextRef bitmap;
  24.     bitmap = CGBitmapContextCreate(NULL, targetSize.width, targetSize.height, CGImageGetBitsPerComponent(imageRef), CGImageGetBytesPerRow(imageRef), colorSpaceInfo, bitmapInfo);    
  25.  
  26.     CGContextDrawImage(bitmap, CGRectMake(1, 1, targetSize.width-2, targetSize.height-2), imageRef);
  27.     CGImageRef ref = CGBitmapContextCreateImage(bitmap);
  28.     UIImage* newImage = [UIImage imageWithCGImage:ref];
  29.  
  30.     CGContextRelease(bitmap);
  31.     CGImageRelease(ref);
  32.  
  33.     NSData * thumbData = UIImagePNGRepresentation(newImage);
  34.     NSData * imageData = UIImagePNGRepresentation(orig);
  35.  
  36.     //Post notification on main thread since it will be updating the UI
  37.     [[NSOperationQueue mainQueue] addOperationWithBlock:^{
  38.         self.tempImageThumbStorage = newImage;
  39.         self.imageThumbnailData = thumbData;
  40.         self.tempImageStorage = orig;
  41.         self.imageData = imageData;
  42.  
  43.         [(AppDelegate*)[UIApplication sharedApplication].delegate saveContext];
  44.  
  45.         NSMutableDictionary * userInfo = [[NSMutableDictionary alloc] initWithCapacity:1];
  46.         [userInfo setObject:[NSNumber numberWithBool:YES] forKey:@"status"];
  47.         [userInfo setObject:self forKey:@"comic"];
  48.  
  49.         [[NSNotificationCenter defaultCenter] postNotificationName:PCRLoadMediahNotification object:self userInfo:userInfo];
  50.         strongSelf = nil;
  51.     }];
  52.  
  53. }