2014-01-17 84 views
0

我有這段代碼在iOS 6中工作正常,但不保存IOS7屏蔽圖像,任何解釋,建議?IOS 7屏蔽問題 - 無法保存屏蔽圖像從uiimageview

//Masking the image 
- (UIImage*) maskImage:(UIImage *)image withMask:(UIImage *)maskImage { 

    CGImageRef maskRef = maskImage.CGImage; 

    CGImageRef mask = CGImageMaskCreate(CGImageGetWidth(maskRef), 
             CGImageGetHeight(maskRef), 
             CGImageGetBitsPerComponent(maskRef), 
             CGImageGetBitsPerPixel(maskRef), 
             CGImageGetBytesPerRow(maskRef), 
             CGImageGetDataProvider(maskRef), NULL, false); 

    CGImageRef masked = CGImageCreateWithMask([image CGImage], mask); 
    return [UIImage imageWithCGImage:masked]; 
} 


- (IBAction)savebtnclicked:(UIButton *)sender { 


    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; 
    NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:@"savedImage2.png"]; 
    UIImage *image = _imageFinal.image; // imageView is my image from camera 
    NSData *imageData = UIImagePNGRepresentation(image); 
    [imageData writeToFile:savedImagePath atomically:NO]; 

} 
+1

它通過一個錯誤,它保存/做任何事情嗎? –

+0

你需要描述它做錯了什麼。也許顯示一些截圖。 – Wain

+0

它不顯示任何錯誤和任何警告 – Ankuribc

回答

0

確保這兩個圖像(要蒙版的圖像和蒙版本身)都有一個alpha通道! 這解決了我在iOS7上的問題。