2012-03-13 3 views
0

возможно поймать ошибку «ImageIO: JPEGMaximum поддерживается размер изображения 65500 пикселей»Поймайте ImageIO: <ERROR>

Я написал попробовать, поймать раздел для соответствующего method.However блок поймать не сделал поймайте исключение ImageIO !!

Этот блок блокировки кода никогда не поймает его. любая помощь в этом оценивается.

-(void)captureToPhotoAlbum { 

    @try {  

     UIImage *image = [self glToUIImage]; //to get an image 

     if (image != nil) { 

      UIImageWriteToSavedPhotosAlbum(image, self, nil, nil); 
      [self eraseView]; 
      [self showAnAlert:@"Saved Successfully" Message:@""]; 

     } 
     else { 

      [self showAnAlert:@"Can't Save!!" Message:@"An error occurred "]; 
     } 



    } 

    @catch (NSException *ex) { 

     [self showAnAlert:@"Can't Save!!" Message:@"An error occurred"]; 
    } 
} 



-(UIImage *) glToUIImage { 

    UIImage *myImage = nil; 

    @try { 


     NSInteger myDataLength = 800 * 960 * 4; 

     // allocate array and read pixels into it. 
     GLubyte *buffer = (GLubyte *) malloc(myDataLength); 
     glReadPixels(0, 0, 800, 960, GL_RGBA, GL_UNSIGNED_BYTE, buffer); 

     // gl renders "upside down" so swap top to bottom into new array. 
     // there's gotta be a better way, but this works. 
     GLubyte *buffer2 = (GLubyte *) malloc(myDataLength); 

     for(int y = 0; y < 960; y++) 
     { 
      for(int x = 0; x < 800 * 4; x++) 
      { 
       buffer2[(959 - y) * 800 * 4 + x] = buffer[y * 4 * 800 + x]; 
      } 
     } 

     // make data provider with data. 
     CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, buffer2, myDataLength, NULL); 

     // prep the ingredients 
     int bitsPerComponent = 8; 
     int bitsPerPixel = 32; 
     int bytesPerRow = 4 * 800; 
     CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB(); 
     CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault; 
     CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault; 

     // make the cgimage 
     CGImageRef imageRef = CGImageCreate(800, 444444444, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent); 

     // then make the uiimage from that 
     myImage = [UIImage imageWithCGImage:imageRef]; 
    } 
    @catch (NSException *ex) { 

     @throw; 
    } 
    @finally { 

     return myImage; 
    } 


} 
+0

Какая линия поднимает исключение? –

ответ

3

метод не вызывает исключения, поэтому нечего улавливать. если вы хотите получить сообщение об ошибке, вы должны передать функцию обратного вызова в качестве третьего аргумента:

UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil); 

, то вы можете реализовать следующий метод, который будет вызываться после того, как изображение будет сохранено:

- (void)   image: (UIImage *) image 
didFinishSavingWithError: (NSError *) error 
      contextInfo: (void *) contextInfo; 
+0

благодарит за информацию –