[英]Resize image and maintain its aspect ratio in iOS
檢查這個博客 。 使用這兩個文件
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];
盡管您的圖片占據了所有屏幕尺寸,但是您的圖片尺寸卻更大了...您可以嘗試按以下分辨率縮放圖片320 * 480、640 * 960、1240 * 2208
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.