2012-05-30 60 views
3

我編寫代碼來裁剪圖像,但我得到圖像的其他部分,而不是在給定的矩形。圖像裁剪給圖像的錯誤部分

CGImageRef cr = CGImageCreateWithImageInRect([imageCrop.image CGImage], rectangle.frame); 
    imageCrop.frame=rectangle.frame; 
    imageCrop.image = [[[UIImage alloc] initWithCGImage:cr] autorelease]; 
    CGImageRelease(cr); 

回答

0

如果您收到這可能是因爲你提供UIImageimageOrientation屬性值的圖像的另一部分。在裁剪之前考慮圖像的方向。

圖像方向會影響繪製時圖像數據的顯示方式。默認情況下,圖像以「向上」的方向顯示。但是,如果圖像具有關聯的元數據(如EXIF信息),則此屬性包含該元數據指示的方向。對於此屬性的可能值的列表,請參閱UIImageOrientation

+0

應該是什麼形象定位? –

+0

@IdreesAshraf我用更多的信息更新了我的答案 – voromax

0
// Try using following line of code- 

    CGImageRef cr = CGImageCreateWithImageInRect([imageCrop.image CGImage], rectangle.frame); 
    imageCrop.image =[UIImage imageWithCGImage:croppedCGImage scale:1.0f orientation:self.imageOrientation]; 
    CGImageRelease(cr); 
+0

再次弄錯了部分 –