Closed ghost closed 8 years ago
(void)imagePickerController:(UIImagePickerController )picker didFinishPickingMediaWithInfo:(NSDictionary<NSString ,id> *)info{
UIImage *selectedImage = info[UIImagePickerControllerEditedImage]?:info[UIImagePickerControllerOriginalImage];
//Scale the image CGSize targetSize = CGSizeMake(selectedImage.size.width * self.selectedImageScale, selectedImage.size.height * self.selectedImageScale); UIGraphicsBeginImageContext(targetSize); [selectedImage drawInRect:CGRectMake(0,0,targetSize.width,targetSize.height)]; UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();
//Compress the image, as it is going to be encoded rather than linked NSData *scaledImageData = UIImageJPEGRepresentation(scaledImage, kJPEGCompression);
Encode the image data as a base64 string NSString *imageBase64String = [scaledImageData base64EncodedStringWithOptions:0];
Decide if we have to insert or update if (!self.imageBase64String) { [self insertImageBase64String:imageBase64String alt:self.selectedImageAlt]; } else { [self updateImageBase64String:imageBase64String alt:self.selectedImageAlt]; }
self.imageBase64String = imageBase64String;
//Dismiss the Image Picker [self.navigationController dismissViewControllerAnimated:YES completion:nil]; }
the method
if (!self.imageBase64String) {
[self insertImageBase64String:imageBase64String alt:self.selectedImageAlt];
} else {
[self updateImageBase64String:imageBase64String alt:self.selectedImageAlt];
}
self.imageBase64String = imageBase64String;
Insert pictures after the first time self.imageBase64String The assigned value The second will go [self updateImageBase64String:imageBase64String alt:self.selectedImageAlt]
Remove the judgment is ok
I noticed that not long after I posted the issue and forgot to update the issue. Thank you for the comment though.
Hi, @xingze0308 , can you explain more about the solution, thank you. 謝謝。
I have an issue with images not displaying, adding the first image is fine but then trying to add any more images just goes through the motions without displaying anything. Also updating images doesn't work.