ギャラリーから画像を取得し、アバターを設定するためのIOSシステム

必ず写真がより多くのマップに拡大していきます将来のような画像を設定するには、バックアップ方法を要約取るためにいくつかのアプリケーションが発生しました

AddCustomerViewControllerの@interface:のUIViewController <UIImagePickerControllerDelegate、UINavigationControllerDelegate> 
{ 
    UIImage * chosenImage; // self.viewに表示された画像を作る 
    のNSString * tempImagePath; // イメージパス 
    UIButton * button_Photo; // クリックシステムは、画像から選択される
} 
@end 
// 上記のすべてのエージェントとは、いくつかのパラメータである必要があります
 
   
- (ボイド)TakePhoto 
{ 
    UIActionSheet * actionSheet = [[UIActionSheet ALLOC] initWithTitle:@ " 您想如何获取照片?"  デリゲート:自己cancelButtonTitle:@" 取消" destructiveButtonTitle:otherButtonTitlesゼロ:" @ 拍照" 、ゼロ]。
   [actionSheet showInView:self.view]。
}
 - (ボイド)actionSheet:(UIActionSheet * )actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
    / * 
    のNSLog( "%のLD"、(長い)buttonIndex @); // 2 --->取消
    UIImagePickerController *ピッカー= [[UIImagePickerController alloc]のinit];
    picker.delegate =自己; 
    picker.allowsEditing = YES;
    IF(buttonIndex == 0)
    {//拍照
        picker.sourceType = UIImagePickerControllerSourceTypeCamera。
    } 
    そうであれば(buttonIndex == 1)
    {//图库
        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary。
    } 
    [自己presentViewController:ピッカーアニメーション:YES完了:NULL]。
      [[UIImagePickerController ALLOC] INIT]。* / 
    のNSLog(@ " %ldの"、(長い)buttonIndex)。// 2 --->取消
   
    場合(buttonIndex == 0 
    { // 拍照 
        UIImagePickerController *ピッカー= 
        ピッカー。デリゲート = 自己;
        picker.allowsEditing = YES; 
        picker.sourceType = UIImagePickerControllerSourceTypeCamera。
        [自己presentViewController:ピッカーがアニメーション:YES完了:NULL]。
    } 
    
    
} 

の#pragma -mark UIImagePickerControllerデリゲート
- (ボイド)imagePickerController:(UIImagePickerController *)ピッカーdidFinishPickingMediaWithInfo:(NSDictionaryの* )の情報
{ 
    chosenImage = [INFO objectForKey:"@ UIImagePickerControllerOriginalImage " ]。
    // 删除缓存文件
    場合([[NSFileManager defaultManager] fileExistsAtPath:tempImagePath]){
        NSLog(「@ 画像が存在しています)。
        NSFileManager * defaultManager。
        
        defaultManager = [NSFileManager defaultManager]。
        NSError *誤差= [[NSError ALLOC] INIT]。
        [defaultManager removeItemAtPath:tempImagePathエラー:エラー]。
        
    } 
    [UIImagePNGRepresentation(chosenImage)WRITETOFILE:[NSTemporaryDirectory()stringByAppendingPathComponent:"@ temp_image.png " アトミック]:YES]。
    
    BOOL FILEEXISTS =[NSFileManager defaultManager] fileExistsAtPath:tempImagePath]。
    
    もし 
                       のInView:self.view(FILEEXISTS){ 
        のNSLog("@ 成功" ); 
        customer_Inform.image_Head = chosenImage。
        [button_Photo setImage:chosenImage forState:UIControlStateNormal]。
        
    } 
    [ピッカーはdismissViewControllerAnimated:YES完了:NULL]。
    
    もし(FILEEXISTS){ 
        のNSLog("@ 成功" ); 
        [SGInfoAlert SHOWINFO:@ " 照片添加成功!" 
                      はbgColor:[[UIColor darkGrayColor] CGColor] 
                     縦:0.5 ]; 
    } 
    
    {
        [SGInfoAlert SHOWINFO:@ " 照片添加不成功!" 
                      はbgColor:[[UIColor darkGrayColor] CGColor] 
                       のInView:self.view 
                     縦:0.5 ]; 
    } 
//     // 也能用
 //     [button_Photo setImage:[情報objectForKey: "UIImagePickerControllerOriginalImage"] @ forState:UIControlStateNormal];
//     [ピッカーはdismissViewControllerAnimated:YES完了:NULL]。
}
 
   

 

 

ます。https://www.cnblogs.com/someonelikeyou/p/3667056.htmlで再現

おすすめ

転載: blog.csdn.net/weixin_34410662/article/details/94538090