【Swift】iOS裁剪或者压缩后出现的白边问题

时间:2023-03-09 08:05:39
【Swift】iOS裁剪或者压缩后出现的白边问题

只需要将所有的CGFloat转化为NSInteger即可

func imageScaleSize(newSize:
CGSize) -> UIImage{

let width =
NSInteger(newSize.width)

let height =
NSInteger(newSize.height)

UIGraphicsBeginImageContext(CGSize(width: width, height: height));

self.drawInRect(CGRect(x:
0, y: 0, width: width, height: height))

let newImage =
UIGraphicsGetImageFromCurrentImageContext()

UIGraphicsEndImageContext();

return newImage;

}