我正在用Swift制作一个调整大小的照片应用程序。我希望它能够在您的iPhone上拍照并在应用程序的相机胶卷中选择一张照片。最后,您可以选择一种尺寸并在该尺寸上获取一张新照片。
您可以选择的尺寸是:
最接近我的理想的应用是:
Image Size
这个应用程式可以随意调整相片大小。
使我感到困扰的是:
例如,即使您可以在2.4x3.0中正确调整iPhone 6相机胶卷中的照片大小,也无法在3.0x4.0中正确调整照片大小。最终图片看起来在纵向延伸。
如果有人想在可选方面调整大小,您能告诉我吗?
谢谢。
调整为3.0x4.0
let cgImage = size1Image.cgImage!.cropping(to: CGRect(x: 0, y: 0, width: 740, height: 720/3.0*4.0))
let croppingImage = UIImage(cgImage: cgImage!)
var resize = croppingImage.ResizeUIImage(width: 353, height: 470)
调整为2.4x3.0
let cgImage = size2Image.cgImage!.cropping(to: CGRect(x: 0, y: 0, width: 720*4.2, height: 720/2.4*3.0*4.0))
let croppingImage = UIImage(cgImage: cgImage!)
let resize = croppingImage.ResizeUIImage(width: 283, height: 354)
调整为3.5x4.5
let cgImage = size3Image.cgImage!.cropping(to: CGRect(x: 0, y: 0, width: 720*4.2, height: 720/3.5*4.5*4.0))
let croppingImage = UIImage(cgImage: cgImage!)
let resize = croppingImage.ResizeUIImage(width: 402, height: 531)
ResizeImage
extension UIImage {
func ResizeUIImage(width : CGFloat, height : CGFloat)-> UIImage!{
UIGraphicsBeginImageContext(CGSize(width: width, height: height))
self.draw(in: CGRect(x: 0, y: 0, width: width, height: height))
let newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return newImage
}
}