我將相互添加2個圖像,並想知道這是否是一種很好的方法?此代碼有效並且看起來很強大。將2個UIImage添加到一個UIImage中
所以,我的問題確實是這樣,還是有更好的辦法?
PS:警告代碼由設計人員編寫。
調用該函數:
- (IBAction) {
UIImage *MyFirstImage = UIImage imageNamed: @"Image.png"];
UIImage *MyTopImage = UIImage imageNamed: @"Image2.png"];
CGFloat yFloat = 50;
CGFloat xFloat = 50;
UIImage *newImage = [self placeImageOnImage:MyFirstImage imageOver:MyTopImage x:&xFloat y:&yFloat];
}
的功能:
- (UIImage*) placeImageOnImage:(UIImage *)image topImage:(UIImage *)topImage x:(CGFloat *)x y:(CGFloat *)y {
// if you want the image to be added next to the image make this CGSize bigger.
CGSize newSize = CGSizeMake(image.size.width,image.size.height);
UIGraphicsBeginImageContext(newSize);
[topImage drawInRect:CGRectMake(*x,*y,topImage.size.width,topImage.size.height)];
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height) blendMode:kCGBlendModeDestinationOver alpha:1];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
難道真的不能改進! – tipycalFlow 2012-03-18 15:37:11