- (void)viewDidLoad {
[superviewDidLoad];
CGRectframe=CGRectMake(520,280,320,480);
CGImageRefsmall;
small=CGImageCreateWithImageInRect([[UIImageimageNamed:@"3.png"]CGImage],frame);
UIImageView*test=[[UIImageViewalloc]initWithImage:[UIImageimageWithCGImage:small]];
[self.viewaddSubview:test];
[testrelease];
}
合成图片的两种方法,思路都是一样的
// Image+Image ICON
- (UIImage*)addImage:(UIImageView*)image1 toImage:(UIImageView*)image2 {
CGSizesize=CGSizeMake( image1.frame.size.width,image1.frame.size.height);
UIGraphicsBeginImageContext(size);
// Draw image1
[image2.image drawInRect:CGRectMake(6,6, image2.frame.size.width, image2.frame.size.height)];
// Draw image2
[image1.image drawInRect:CGRectMake(0,0, image1.frame.size.width, image1.frame.size.height)];
UIImage*resultingImage =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
returnresultingImage;
}
- (UIImage*)addImageview:(UIImage*)image1 toImage:(UIImage*)image2 {
CGSizesize=CGSizeMake( image1.size.width,image1.size.height);
UIGraphicsBeginImageContext(size);
// Draw image1
[image2drawInRect:CGRectMake(4.5,6,77,77)];
// Draw image2
[image1drawInRect:CGRectMake(0,0, image1.size.width, image1.size.height)];
UIImage*resultingImage =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
returnresultingImage;
}