Picture loaded from Camera Roll too stretched in portrait mode

I am having trouble with UIView which is feeding by an image from Camera Roll.

When I pick a picture which was taken in the portrait mode the view always stretch the picture too high, but when I rotate my device the picture is stretched fine.


- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    if(info){
        {
            [artView removeFromSuperview];
            artView = nil;
            artView = [[UIImageView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];

            artView.image = [info objectForKey:UIImagePickerControllerOriginalImage];
            artView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
            artView.contentMode = UIViewContentModeScaleAspectFill;

[self.contentView addSubview:artView];

Any help is appreciated.


如果其他人仍然有这个问题尝试在contentMode后设置图像。

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    if (info) {
        [artView removeFromSuperview];
        artView = [[UIImageView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];

        artView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
        artView.contentMode = UIViewContentModeScaleAspectFill;
        artView.image = [info objectForKey:UIImagePickerControllerOriginalImage];

        [self.contentView addSubview:artView];
        [artView release];
    }
}

Your code looks good except it leaks and you have too many opening braces and no closing braces.

You probably want it to look like this:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    if (info) {
        [artView removeFromSuperview];
        artView = [[UIImageView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];

        artView.image = [info objectForKey:UIImagePickerControllerOriginalImage];
        artView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
        artView.contentMode = UIViewContentModeScaleAspectFill;

        [self.contentView addSubview:artView];
        [artView release];
    }
}

UIViewContentModeScaleAspectFill shouldn't stretch the image. It should clip it. Perhaps UIViewContentModeScaleAspectFit is what you're looking for?

链接地址: http://www.djcxy.com/p/84306.html

上一篇: MFMailComposer发送附加的图像大小增加

下一篇: 从相机胶卷加载的照片在肖像模式下拉得太紧