gpt4 book ai didi

iphone - 将 2 个 UIImage 添加到一个 UIImage

转载 作者:行者123 更新时间:2023-11-28 17:36:13 24 4
gpt4 key购买 nike

我正在将 2 张图片相互添加,想知道这是否是一个好方法?这段代码有效并且看起来很强大。

所以,我的问题真的是,这样好还是有更好的方法?

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;
}

最佳答案

看起来不错。也许您并不真的需要 CGFloat 指针,但这也没关系。

关于iphone - 将 2 个 UIImage 添加到一个 UIImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9759510/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com