我有2个ImageView。我想将图像从库加载到ImageView。我的要求是,如果我第一次选择图像,则应将图像加载到ImageView 1中,当我第二次选择图像时,应将图像加载到ImageView 2中。
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo :(NSDictionary *)info
{
int count=0;
iscamera=YES;
_imageuser.image=[info objectForKey:UIImagePickerControllerOriginalImage];
_imageuser1.image=[info objectForKey:UIImagePickerControllerOriginalImage];
_imageuser2.image=[info objectForKey:UIImagePickerControllerOriginalImage];
if (ipc.sourceType == UIImagePickerControllerSourceTypeSavedPhotosAlbum) {
if (count==0) {
pngData = UIImagePNGRepresentation(_imageuser.image);
pngData = UIImagePNGRepresentation(_imageuser1.image);
}
else if (count== 1)
{
pngData = UIImagePNGRepresentation(_imageuser.image);
pngData = UIImagePNGRepresentation(_imageuser2.image);
}
count ++;
}
else{
pngData = UIImagePNGRepresentation([self rotateUIImage:_imageuser.image clockwise:YES]);
}
[picker dismissViewControllerAnimated:YES completion:nil];
}
答案 0 :(得分:0)
//initialize count with 0
let count = 0
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
imagePicker.dismiss(animated: true, completion: nil)
// get image
let capturedImage = info[UIImagePickerControllerOriginalImage] as? UIImage
// you can set image to any imageview according to count value
if(count == 0){
firstImageView.image = capturedImage
}else if (count == 1){
secondImageView.image = capturedImage
}else{
}
// increment count so that we can set image to appropriate image view
count ++
}
答案 1 :(得分:0)
您可以在image1中检查图像的NSdata。 如果存在,则将第二个所选图像提供给第二个imageView,否则将其提供给第一个imageView。