1本文摘自:http://dev.10086.cn/cmdn/wiki/index.php?doc-view-3563.html
- #import <Foundation/Foundation.h>
-
-
- @interface UIImage (scale)
-
- -(UIImage*)scaleToSize:(CGSize)size;
-
- @end
-
-
-
-
-
-
-
-
- #import "UIImageScale.h"
-
-
-
- @implementation UIImage (scale)
-
- -(UIImage*)scaleToSize:(CGSize)size
- {
-
-
- UIGraphicsBeginImageContext(size);
-
-
- [self drawInRect:CGRectMake(0, 0, size.width, size.height)];
-
-
- UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
-
-
- UIGraphicsEndImageContext();
-
-
- return scaledImage;
- }
-
- @end
调用:
- CGSize imageSize = CGSizeMake(imageWidth, imageHeigh) ;
-
- holeImage = [holeImage scaleToSize:imageSize];
-
- CGRect imageframe = CGRectMake(0, 85, holeImage.size.width, holeImage.size.height);
-
-
- [holeImage drawInRect:imageframe ];