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

我遇到了UIView的问题,它是由Camera Roll中的图像提供的。

当我选择在肖像模式下拍摄的照片时,该视图总是将照片拉得太高,但是当我旋转我的设备时,照片拉伸得很好。


- (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];

任何帮助表示赞赏。


如果其他人仍然有这个问题尝试在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];
    }
}

你的代码看起来不错,只是它泄漏了,你有太多的开口花括号和没有花括号。

你可能希望它看起来像这样:

- (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不应该拉伸图像。 它应该剪辑它。 也许UIViewContentModeScaleAspectFit是你在找什么?

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

上一篇: Picture loaded from Camera Roll too stretched in portrait mode

下一篇: Capture Video of Android's Screen