photoview bugbugcommunity什么意思

ios - UIImagePickerController bug - Stack Overflow
to customize your list.
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.
J it only takes a minute:
Join the Stack Overflow community to:
Ask programming questions
Answer and help your peers
Get recognized for your expertise
I think I found a bug in latest iOS 7 by running an app with Base SDK set to iOS 6.1 (possibly even lower versions too, haven't tested that out yet)
I have this image in my photo library:
I present a UIImagePickerController via:
UIImagePickerController *vc = [[UIImagePickerController alloc] init];
vc.sourceType = UIImagePickerControllerSourceTypePhotoL
vc.delegate =
vc.allowsEditing = YES;
[self presentViewController:vc animated:YES completion:nil];
I save the chosen image to my desktop (I am running this on simulator, but this works on device too)
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage* outputImage = [info objectForKey:UIImagePickerControllerEditedImage];
if (outputImage == nil) {
outputImage = [info objectForKey:UIImagePickerControllerOriginalImage];
NSData *d = UIImagePNGRepresentation(outputImage);
[d writeToFile:@"/Users/Admin/Desktop/test.png" atomically:YES];
[self dismissViewControllerAnimated:YES completion:nil];
This is the resulting image:
Notice the big black bar to the right. What's causing this?
To reproduce this, you need:
App with Base SDK set to 6.1 (maybe even lower SDKs too, i haven't tried yet)
iPhone 5/5c/5s
Only happens to pictures that were taken with iPhone 5/5c/5s camera (you can use the original image I linked above for testing)
NOTE: Just to be clear, the black bar is part of the actual image. The image you see there is not a screenshot of a UIImageView, but the actual image saved to disk and uploaded here...
11.8k640106
4,1621783187
Your question is "What's causing this?" So I'll focus on that instead of giving a workaround.
This is definitely a bug in iOS 7 dealing with edited images in lower base SDKs. We can also rule out that XCode 5 & Base SDK 6.1 causing this because I'm getting the same issue with XCode 4.6.3 & 6.1 SDK running on iOS 7 Simulator.
The source of the problem is that the CropRect values that are calculated by the SDK are wrong.
If you'll print out the info NSDictionary from imagePickerController:didFinishPickingMediaWithInfo you'll see that:
iOS 7 running any SDK lower than 7 we'll get:
UIImagePickerControllerCropRect = "NSRect: {{154, 495}, {1705,
While running iOS 6 or 5 with their SDK will give us:
UIImagePickerControllerCropRect = "NSRect: {{0, 149}, {1704,
You're probably saying, hmm, those y values are changing between SDKs too. Well, yea, if you'll slide your pic all the way down and select it you'll also get a black bar at the bottom of the picture.
Suggested Solutions:
...Did that!
Don't use UIImagePickerControllerEditedImage and take the original picture instead.
Calculate and do the cropping your self.
Use a 3rd party cropping library such as
Edit - very simple solution added by fan of the answer!
Amazingly, it can be this simple and elegant to crop it yourself:
// There is a bug in iOS. When using ALBUM, you must crop it yourself:
fromAlbum = [info objectForKey:UIImagePickerControllerOriginalImage];
fromAlbum = [fromAlbum fixOrientation];
CGRect crop = [[info valueForKey:@"UIImagePickerControllerCropRect"] CGRectValue];
fromAlbum = [self ordinaryCrop:fromAlbum toRect:crop];
Here's the whole routine ordinaryCrop:toRect:
-(UIImage *)ordinaryCrop:(UIImage *)imageToCrop toRect:(CGRect)cropRect
CGImageRef imageRef = CGImageCreateWithImageInRect([imageToCrop CGImage], cropRect);
UIImage *cropped = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
Now as Jesse points out, it is critical to rotate the image properly. This absolutely incredible piece of code by Anomie does the job:
Fixing UIImage orientation .. UIImage+fixOrientation.h
It's that simple, hope it helps someone. Thanks again for the priceless answers here.
15.7k16107212
11.8k640106
I believe we ended up working around similar issues by never asking for the e ask for the original image and the crop information (UIImagePickerControllerCropRect) and do the cropping yourself. Note that you need to worry about rotations in the source image if you do the cropping yourself.
You might find the
helpful for implementing this work-around.
43.1k107888
Try find and change mode (Aspect Fit, Aspect Fill, Scale to Fill) programmatically.
I'm trying to reproduce this bug. And have no luck on simulator, simulator 64-bit and iPad mini. All running iOS 7.0.
I put your code in my app:
UIImage *image = [info valueForKey:UIImagePickerControllerEditedImage];
if (!image)
image = [info valueForKey:UIImagePickerControllerOriginalImage];
// Save photo to custom album only if taken by camera
if (picker.sourceType == UIImagePickerControllerSourceTypeCamera)
[ALAssetsLibrary saveImageToCustomAlbum:image
assetURL:[info valueForKey:UIImagePickerControllerReferenceURL]];
NSData *d = UIImagePNGRepresentation(image);
[d writeToFile:@"/Volumes/Alko/Temp/test.png" atomically:YES];
UIImageWriteToSavedPhotosAlbum(image, nil, NULL, nil);
[self setImage:image];
[self dismissPicker:picker];
[self photoPickerDidFinish];
And it works correct using image downloaded from .
I think you have issue in your app, not in UIImagePickerController.
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
The week's top questions and answers
Important community announcements
Questions that need answers
By subscribing, you agree to the
Stack Overflow works best with JavaScript enabled}

我要回帖

更多关于 live photo什么意思 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信