UIImageView Stretches中的图像

时间:2012-12-10 07:54:57

标签: ios xcode uiimageview uiimage

我在stackoverflow上看到了同一个问题的不同帖子,但没有一个对我有用,因此我发布了我的查询

我正在开发一个应用程序,我从图库中挑选图像并将其放在我的UIImageView实例上

drawImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"abc.png"]];
[drawImage setContentMode:UIViewContentModeScaleToFill];
drawImage.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
drawImage.clipsToBounds = YES;

[drawImage setFrame:self.view.frame];
NSLog(@"%@",NSStringFromCGSize(drawImage.frame.size));
[self.view addSubview:drawImage];

这是图片库的代码

imagePickerObj.sourceType=UIImagePickerControllerSourceTypeSavedPhotosAlbum;
imagePickerObj.allowsEditing=YES;

当我从图库中选择图像时,我正在使用以下代码

UIImage *img = [info objectForKey:UIImagePickerControllerEditedImage];
NSLog(@" B4 crop Image size %@",NSStringFromCGSize(img.size));
NSLog(@" B4 crop DrawImage size %@",NSStringFromCGSize(drawImage.frame.size));

UIGraphicsBeginImageContext(drawImage.frame.size);
[img drawInRect:CGRectMake(0,0,drawImage.frame.size.width,drawImage.frame.size.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();

NSLog(@"After crop Image size %@",NSStringFromCGSize(newImage.size));
UIGraphicsEndImageContext();


// drawImage.clipsToBounds = YES;
drawImage.image = newImage;

问题在于,无论我选择什么图像,它总是看起来有点拉伸,我为UIGraphicsBeginImageContext添加了上面的代码,它减少了图像的宽度和高度,但它仍然显得拉伸

我甚至尝试将图片视图的内容模式更改为AspectFillAspectFit,但根本没有运气。

你能指导我出错吗?

0 个答案:

没有答案