我正在尝试从照片库中选择一张图片,这是我从网上下载并存储在照片库中的照片。
所以现在我想给用户一个选择从照片库中选择图像并在我的应用程序中作为backgroundImage应用的选项,但是当我这样做时,我会在我的iphone屏幕上以这种方式获取图像
实际上图像已经填满了屏幕,因为指定的内容模式是" scaleToFill"。
1)我想知道如何使这个图像保持其宽高比并填充屏幕?
此致 兰吉特
答案 0 :(得分:2)
检查this blog。使用这两个文件
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];
答案 1 :(得分:0)
虽然您的图像占据了所有屏幕尺寸,但您的图像尺寸却比较大......您将尝试使用以下分辨率缩放图像 320 * 480, 640 * 960, 1240 * 2208