gpt4 book ai didi

iphone - 从两个 UIImageView 创建一个 UIImage

转载 作者:行者123 更新时间:2023-12-03 18:38:36 27 4
gpt4 key购买 nike

我的UIView上有两个UIImageView。每个 UIImageView 有一个 UIImage。现在我想从两个 UIImageView 创建一个 UIImage。

请给我建议,我该怎么做。

最佳答案

如果您有一个包含三个 UIImageView 的 View 并创建相应的导出

IBOutlet UIImageView *imageView1;
IBOutlet UIImageView *imageView2;
IBOutlet UIImageView *imageView3;

您可以执行类似以下操作将 imageView 1 和 2 合并到 imageView 3

UIGraphicsBeginImageContext(imageView1.image.size);  

CGRect rect = CGRectMake(0, 0, imageView1.image.size.width, imageView1.image.size.height);

[imageView1.image drawInRect:rect];
[imageView2.image drawInRect:rect blendMode:kCGBlendModeScreen alpha:0.5];

UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

[imageView3 setImage:resultingImage];

CGBlendMode 允许您为图像选择以下任何合成操作:

enum CGBlendMode {
kCGBlendModeNormal,
kCGBlendModeMultiply,
kCGBlendModeScreen,
kCGBlendModeOverlay,
kCGBlendModeDarken,
kCGBlendModeLighten,
kCGBlendModeColorDodge,
kCGBlendModeColorBurn,
kCGBlendModeSoftLight,
kCGBlendModeHardLight,
kCGBlendModeDifference,
kCGBlendModeExclusion,
kCGBlendModeHue,
kCGBlendModeSaturation,
kCGBlendModeColor,
kCGBlendModeLuminosity,
kCGBlendModeClear,
kCGBlendModeCopy,
kCGBlendModeSourceIn,
kCGBlendModeSourceOut,
kCGBlendModeSourceAtop,
kCGBlendModeDestinationOver,
kCGBlendModeDestinationIn,
kCGBlendModeDestinationOut,
kCGBlendModeDestinationAtop,
kCGBlendModeXOR,
kCGBlendModePlusDarker,
kCGBlendModePlusLighter
};

关于iphone - 从两个 UIImageView 创建一个 UIImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2005436/

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