如何在两个维度上同等地将UIImage缩小一半?
我有一个UIImage的大小是UIImageView的两倍,并希望它是相同的大小,而不使用任何填充或缩放等内容模式。
发布于 2012-08-11 05:41:02
只需为自己创建一个新图像(表示为UIImage的一个类别方法):
- (UIImage*)scaleToSize:(CGSize)size {
UIGraphicsBeginImageContext(size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(context, 0.0, size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextDrawImage(context, CGRectMake(0.0f, 0.0f, size.width, size.height), self.CGImage);
UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return scaledImage;
}https://stackoverflow.com/questions/11909502
复制相似问题