您的位置:首页 > 其它

合成图片的两种方法,思路都是一样的

2013-01-18 09:48 253 查看
- (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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: