2012-03-13 24 views
0

是有可能捕獲錯誤「的ImageIO:JPEG大小支持的圖像尺寸是65500個像素」捕捉的ImageIO:<ERROR>

我已經寫了嘗試,爲相應的method.However catch塊沒趕上節捕捉ImageIO異常!

下面的代碼catch塊永遠不會捕獲它。任何幫助這是讚賞。

-(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

哪條線引發異常? – 2012-03-13 17:27:39

回答

3

該方法不會拋出異常,所以沒有什麼可以捕捉的。如果你想收到錯誤消息時,應傳遞一個回調作爲第三個參數:

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

那麼你就可以實現下面的方法,將被調用一次保存圖像:

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

感謝您的信息 – 2012-03-14 14:59:21