coding with objc & swift

缩放UIImage到指定大小

| Comments

1
2
3
4
5
6
7
8
9
10
11
//将originImage缩放到指定大小newSize。
//用处:originImage太大时,缩放到指定大小后,可以释放originImage从而减少内存占用。
+ (UIImage *)scaledImageFromImage:(UIImage *)originImage toSize:(CGSize)newSize
{
	UIGraphicsBeginImageContext(newSize);
	[originImage drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
	UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
	UIGraphicsEndImageContext();
	
	return newImage;
}

Comments