2012-10-22 28 views
2

我使用的UIImagePickerController的屬性allowsEditing設置爲YESUIImagePickerController檢查用戶是否編輯了圖像

當用戶完成選擇圖像時,我想知道用戶是否編輯了他選擇或不選擇的圖像(例如,如果他縮放了圖像)。此方法:

UIImage *editedImage = [info objectForKey:@"UIImagePickerControllerEditedImage"]; 

即使用戶離開照片,它總是返回一個對象。有什麼方法可以檢查用戶是否編輯了圖像?例如,我可以檢查UIImagePickerControllerEditedImageUIImagePickerControllerOriginalImage是不同的嗎?

回答

7

didFinishPickingMediaWithInfo試試這個,因爲我不知道:

UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage]; 

UIImage *editedimage = [info objectForKey:UIImagePickerControllerEditedImage]; 

if ([UIImagePNGRepresentation(image) isEqualToData:UIImagePNGRepresentation(editedimage)]) 
    //not edited 
else 
    //edited 
+1

此數據將永遠不會相同,因爲默認情況下,編輯圖像默認包含600 x 600圖像,無論原始圖像大小是多少,用戶是否與圖像進行交互以進行編輯,編輯圖像鍵將包含圖像 - 在作物長度。 –

0
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage]; 

UIImage *editedimage = [info objectForKey:UIImagePickerControllerEditedImage]; 
if(editedimage.length>0){ 
//then got the edited image 
} 
+1

image和editedImage都會有數據 –

0

會不只是得到和比較形象的CGSize?

BOOL sizeChanged = FALSE; 

// get current size of image 
CGSize originalSize = [image size]; 

//After the user hase made the action, get the new size 
CGSize currentSize = [image size]; 

// if the dimensions have been editied the condition is true 
if (originalSize.width != currentSize.width || 
    originalSize.height != currentSize.height 
    ) 
    sizeChanged = TRUE; 
else 
    sizeChanged = FALSE; 
0

檢查了這一點:

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIImagePickerControllerDelegate_Protocol/UIImagePickerControllerDelegate/UIImagePickerControllerDelegate.html#//apple_ref/doc/uid/TP40007069

這是ImagePicker代表的文檔。正如你所看到的,當用戶鎬和圖像這就是所謂的:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 

信息 - 是包含發生了什麼,什麼已經拾取數據字典。如果允許設置爲YES,則info包含原始圖像和編輯的圖像。檢查鏈接我給你的

編輯信息鍵

有一堆的常量存在,可以給你你所尋求的數據!

從這裏開始看到整個機械: http://developer.apple.com/library/ios/documentation/uikit/reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html#//apple_ref/occ/instp/UIImagePickerController/allowsEditing

0

我知道,這是一個非常古老的問題,在一段時間沒有活動,但是這是在谷歌搜索出現,並儘可能我可以說,這個問題還沒有得到滿意的答覆。

無論如何,說句題外話,如果圖像已被編輯或不能是這樣的:

在didFinishPickingMediaWithInfo:您可以檢查CropRect的寬度和原始圖像的寬度。如果CropRect.width == originalImage.width + 1,那麼它尚未被編輯。這是真的原因是因爲編輯圖像,用戶必須捏和放大,這縮放圖像和改變CropRect的大小。只是簡單地移動圖像將不會工作,因爲它會反彈回來,除非它被縮放。

NSValue *pickerCropRect = info[UIImagePickerControllerCropRect]; 
CGRect theCropRect = pickerCropRect.CGRectValue; 

UIImage *originalImage = info[UIImagePickerControllerOriginalImage]; 
CGSize originalImageSize = originalImage.size; 

if (theCropRect.size.width == originalImageSize.width+1) { 
    NSLog(@"Image was NOT edited."); 
} else { 
    NSLog(@"Image was edited."); 
} 

據我可以告訴這適用於iOS 6在6S和6+。我沒有看到它不應該在其他地方工作的真正原因。

相關問題