ios從相機或相冊獲取圖片并裁剪

ios從相機或相冊獲取圖片并裁剪

ID:34416873

大小:49.50 KB

頁數(shù):3頁

時間:2019-03-05

ios從相機或相冊獲取圖片并裁剪_第1頁
ios從相機或相冊獲取圖片并裁剪_第2頁
ios從相機或相冊獲取圖片并裁剪_第3頁
資源描述:

《ios從相機或相冊獲取圖片并裁剪》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在工程資料-天天文庫。

1、iOS從相機或相冊獲取圖片并裁剪需要從相冊或者相機中讀取圖片。代碼很簡單,抽取關(guān)鍵部分,如下:?//loaduserimage-(void)UesrImageClicked{UIActionSheet*sheet;//判斷是否支持相機if([UIImagePickerControllerisSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){sheet=[[UIActionSheetalloc]initWithTitle:@"選擇圖像"delegate:selfcancelButtonTitle:nild

2、estructiveButtonTitle:@"取消"otherButtonTitles:@"拍照",@"從相冊選擇",nil];}else{sheet=[[UIActionSheetalloc]initWithTitle:@"選擇圖像"delegate:selfcancelButtonTitle:nildestructiveButtonTitle:@"取消"otherButtonTitles:@"從相冊選擇",nil];}sheet.tag=255;[sheetshowInView:self.view];}#pragmamark-actionsheetdelegte-(vo

3、id)actionSheet:(UIActionSheet*)actionSheetclickedButtonAtIndex:(NSInteger)buttonIndex{if(actionSheet.tag==255){NSUIntegersourceType=UIImagePickerControllerSourceTypePhotoLibrary;//判斷是否支持相機if([UIImagePickerControllerisSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){switch(butto

4、nIndex){case0:return;case1://相機sourceType=UIImagePickerControllerSourceTypeCamera;break;case2://相冊sourceType=UIImagePickerControllerSourceTypePhotoLibrary;break;}}else{if(buttonIndex==0){return;}else{sourceType=UIImagePickerControllerSourceTypeSavedPhotosAlbum;}}//跳轉(zhuǎn)到相機或相冊頁面UIImagePickerCon

5、troller*imagePickerController=[[UIImagePickerControlleralloc]init];imagePickerController.delegate=self;imagePickerController.allowsEditing=YES;imagePickerController.sourceType=sourceType;[selfpresentViewController:imagePickerControlleranimated:YEScompletion:^{}];}}#pragmamark-imagepickerdel

6、egte-(void)imagePickerController:(UIImagePickerController*)pickerdidFinishPickingMediaWithInfo:(NSDictionary*)info{[pickerdismissViewControllerAnimated:YEScompletion:^{}];UIImage*image=[infoUIImagePickerControllerOriginalImage];userImageView.image=image;NSData*imageData=UIImageJPEGRepresent

7、ation(image,COMPRESSED_RATE);UIImage*compressedImage=[UIImageimageWithData:imageData];[HttpRequestManageruploadImage:compressedImagehttpClient:self.httpClientdelegate:self];}創(chuàng)建一張表單,選擇相機或者相冊,然后用回調(diào)函數(shù)處理返回的圖片。但是返回的圖像并不是正方形,顯示在用戶頭像的View里面產(chǎn)生明顯的拉伸。研究了很久各種裁剪算法,甚

當(dāng)前文檔最多預(yù)覽五頁,下載文檔查看全文

此文檔下載收益歸作者所有

當(dāng)前文檔最多預(yù)覽五頁,下載文檔查看全文
溫馨提示:
1. 部分包含數(shù)學(xué)公式或PPT動畫的文件,查看預(yù)覽時可能會顯示錯亂或異常,文件下載后無此問題,請放心下載。
2. 本文檔由用戶上傳,版權(quán)歸屬用戶,天天文庫負(fù)責(zé)整理代發(fā)布。如果您對本文檔版權(quán)有爭議請及時聯(lián)系客服。
3. 下載前請仔細(xì)閱讀文檔內(nèi)容,確認(rèn)文檔內(nèi)容符合您的需求后進行下載,若出現(xiàn)內(nèi)容與標(biāo)題不符可向本站投訴處理。
4. 下載文檔時可能由于網(wǎng)絡(luò)波動等原因無法下載或下載錯誤,付費完成后未能成功下載的用戶請聯(lián)系客服處理。