iOS 图片拼接技术
- (void)viewDidLoad {
[super viewDidLoad];
CGRect frame= CGRectMake(520, 280, 320, 480);
CGImageRef small;
small= CGImageCreateWithImageInRect([[UIImage imageNamed:@"3.png"] CGImage],frame);
UIImageView *test=[[UIImageView alloc] initWithImage:[UIImage imageWithCGImage:small]];
[self.view addSubview:test];
[test release];
}
合成图片的两种方法,思路都是一样的
// Image+Image ICON
- (UIImage *)addImage:(UIImageView *)image1 toImage:(UIImageView *)image2 {
CGSize size= 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();
return resultingImage;
}
- (UIImage *)addImageview:(UIImage *)image1 toImage:(UIImage *)image2 {
CGSize size= CGSizeMake( image1.size.width,image1.size.height);
UIGraphicsBeginImageContext(size);
// Draw image1
[image2 drawInRect:CGRectMake(4.5, 6, 77, 77)];
// Draw image2
[image1 drawInRect:CGRectMake(0, 0, image1.size.width, image1.size.height)];
UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return resultingImage;
}