UIImage 图片缩放

uiimage 图片缩放

 

#import <Foundation/Foundation.h>


@interface UIImage (scale)

-(UIImage*)scaleToSize:(CGSize)size;

@end

 

//
//  UIImageScale.m
//  golfChina
//
//  Created by chao.wang on 6/1/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "UIImageScale.h"



@implementation UIImage (scale)

-(UIImage*)scaleToSize:(CGSize)size
{
	// 创建一个bitmap的context
	// 并把它设置成为当前正在使用的context
	UIGraphicsBeginImageContext(size);
	
	// 绘制改变大小的图片
	[self drawInRect:CGRectMake(0, 0, size.width, size.height)];
	
	// 从当前context中创建一个改变大小后的图片
	UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
	
	// 使当前的context出堆栈
	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 ];
 

 

 

你可能感兴趣的:(uiimage)