我有两个UIImageViews,我已经设法合并并保存它们。但是我希望覆盖的图像能够相对于所选图像的比例进行缩放和定位。因此,您在屏幕上看到的UIImageView看起来与它保存的UIImageView相同。
- (UIImage *)combineImages{
UIGraphicsBeginImageContext(CGSizeMake(theimageView.image.size.width,theimageView.image.size.height));
// Draw image1
[theimageView.image drawInRect:CGRectMake(0,0, theimageView.image.size.width,theimageView.image.size.height)];
// Draw image2
[Birdie.image drawInRect:CGRectMake(Birdie.center.x, Birdie.center.y, (theimageView.image.size.width / 2), (theimageView.image.size.height / 2))];
UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return resultingImage;
}
theImageView和Birdie是两个UIImageViews。 先谢谢!
答案 0 :(得分:0)
请试试这个,
- (UIImage *)combineImages{
// Draw image1
[theimageView.image drawInRect:CGRectMake(0,0, theimageView.image.size.width,theimageView.image.size.height)];
// Draw image2
[Birdie.image drawInRect:CGRectMake(Birdie.frame.origin.x, Birdie.frame.origin.y, Birdie.frame.size.width, Birdie.frame.size.height)];
//have you added Birdie over theimageView if not than do this. If your size is already set as you want then there is no need for above two lines of drawInRect.
UIGraphicsBeginImageContext(theimageView.bounds.size);
[theimageView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return resultingImage;
}
谢谢,