【问题标题】:Resize image and maintain its aspect ratio in iOS在 iOS 中调整图像大小并保持其纵横比
【发布时间】:2015-07-22 11:06:54
【问题描述】:

我正在尝试从照片库中选择一张图片,这是我从网上下载并存储在我的照片库中的照片

所以现在我想给用户一个选项来从照片库中选择一个图像并通过我的应用程序作为背景图像应用,但是当我这样做时,我会在我的 iPhone 屏幕上以这种方式获取图像

实际上图片已经填满了屏幕,因为指定的内容模式是“scaleToFill”。

1) 我想知道如何让这张图片保持其纵横比并填满屏幕?

问候 兰吉特

【问题讨论】:

  • 可以使用Aspectfit
  • 您是否使用情节提要?

标签: ios uiimage uikit uiimagepickercontroller


【解决方案1】:

检查this blog。使用这两个文件

UIImage+Resize.h

UIImage+Resize.m

UIImage *image = [UIImage imageNamed:@"SomeImage-900x675"]; // SomeImage-900x675.png 
CGFloat targetWidth = 320.0;
CGFloat scaleFactor = targetWidth / image.size.width; 
CGFloat targetHeight = image.size.height * scaleFactor; 
CGSize targetSize = CGSizeMake(targetWidth, targetHeight);
UIImage *scaledImage = [image resizedImage:targetSize interpolationQuality:kCGInterpolationHigh];

【讨论】:

    【解决方案2】:

    虽然您的图像占用了所有屏幕尺寸,但您的图像尺寸更大...您将尝试使用以下分辨率缩放图像 320*480, 640*960, 1240*2208

    【讨论】:

    • 但是缩放后渲染是否正确?
    猜你喜欢
    • 2012-11-15
    • 2013-06-26
    • 2012-04-15
    • 2019-08-10
    • 2012-05-01
    相关资源
    最近更新 更多