Convert UIImage to NSData and save with core data

前端 未结 8 773
不知归路
不知归路 2021-01-30 18:43

I have a UIImageView whose image gets set via UIImagePicker

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPi         


        
8条回答
  •  别那么骄傲
    2021-01-30 18:55

    This code save your image data into filedata and you can use it anywhere

    -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image1 editingInfo:(NSDictionary *)editingInfo
    {
    
        {
    
            CGSize destinationSize = CGSizeMake(170,170);
    
            UIGraphicsBeginImageContext(destinationSize);
    
           [image1 drawInRect:CGRectMake(0,0,destinationSize.width,destinationSize.height)];
    
           UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    
           UIGraphicsEndImageContext();
    
           NsData *filedata  = UIImagePNGRepresentation(newImage);
    
           [picker dismissModalViewControllerAnimated:YES];
       }
    }
    

提交回复
热议问题