tencent cloud

腾讯特效 SDK

iOS

下载
聚焦模式
字号
最后更新时间: 2026-11-24 17:37:01
本文档已由 AI 辅助审校

功能说明

TEBeautyKit 是腾讯特效美颜模块的 UI 面板库,用于客户快速方便的使用和管理美颜功能,效果如下图:


集成步骤

1. 集成 TEBeautyKit,编辑 podfile 文件,添加下面的代码后执行 pod install。
# 将S1-07替换成您购买的套餐,注意TEBeautyKit和TencentEffect要使用相同套餐
pod 'TEBeautyKit/S1-07', :podspec => 'https://mediacloud-76607.gzc.vod.tencent-cloud.com/TencentEffect/iOS/TEBeautyKit/latest/TEBeautyKit.podspec'
pod 'TencentEffect_S1-07', :podspec => 'https://mediacloud-76607.gzc.vod.tencent-cloud.com/TencentEffect/iOS/podspec/latest/TencentEffect_S1-07.podspec'
2. 集成 面板资源,点击下载资源包后,引入主工程,内容说明见 附录。
3. 集成 美颜素材。

使用指引

步骤一:鉴权

使用 SDK 前,需要进行一次美颜鉴权,鉴权成功后才能正常使用美颜功能,详见 鉴权错误码 说明。
[TEBeautyKit setTELicense:@"your license" key:@"your key" completion:^(NSInteger authresult, NSString * _Nullable errorMsg) {
NSLog(@"----------result: %zd %@",authresult,errorMsg);
}];

步骤二:配置面板资源路径

美颜面板上面的美颜数据、icon 图标都在 面板资源 中,根据接口说明,传入对应的 json 文件路径,面板上显示的内容可以根据实际需求自行调整。
4.4.0及之后版本
4.4.0之前版本
/// 4.4.0新增配置方法,同时兼容旧版配置方法
- (void)configPanel {
NSString *indexPath = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"json"];
// 配置套餐和index路径,此处以S1_07套餐为例
[[TEUIConfig shareInstance] setPanelViewRes:indexPath effectPlanName:TEEffectPlan_S1_07];
}
- (void)configPanel {
NSBundle *bundle = [NSBundle mainBundle];
NSString *beautyJsonPath = [bundle pathForResource:@"beauty" ofType:@"json"]; //美颜
NSString *lutJsonPath = [bundle pathForResource:@"lut" ofType:@"json"]; //滤镜
NSString *motion2dJsonPath = [bundle pathForResource:@"motion_2d" ofType:@"json"]; //2d贴纸
NSMutableArray *resArray = [[NSMutableArray alloc] init];
[resArray addObject:@{TEUI_BEAUTY : beautyJsonPath}];
[resArray addObject:@{TEUI_LUT : lutJsonPath}];
[resArray addObject:@{TEUI_MOTION_2D : motion2dJsonPath}];
/// 设置资源
[[TEUIConfig shareInstance] setTEPanelViewResources:resArray];
}

步骤三:添加面板

TEPanelView 是自定义的面板视图,用来展示步骤二中配置的数据。
- (void)addPanelView {
TEPanelView *tePanelView = [[TEPanelView alloc] init];
tePanelView.delegate = self;
[self.view addSubview:tePanelView];
[tePanelView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.bottom.mas_equalTo(self.view);
make.left.right.mas_equalTo(self.view);
make.height.mas_equalTo(230 + self.view.safeAreaInsets.bottom);
}];
}

步骤四:使用美颜

1. 初始化
- (void)initXMagic {
__weak typeof(self)weakSelf = self;
[TEBeautyKit createXMagic:EFFECT_MODE_PRO onInitListener:^(TEBeautyKit * _Nullable beautyKit) {
__strong typeof(weakSelf)strongSelf = weakSelf;
strongSelf.teBeautyKit = beautyKit;
strongSelf.tePanelView.teBeautyKit = strongSelf.teBeautyKit;
[strongSelf.tePanelView setDefaultBeauty];
}];
}
2. 处理视频数据
#pragma mark AVCaptureVideoDataOutputSampleBufferDelegate
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection {
if (captureOutput == self.videoDataOutput) {
[self mycaptureOutput:captureOutput didOutputSampleBuffer:sampleBuffer fromConnection:connection originImageProcess:YES];
}
}

- (void)mycaptureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)inputSampleBuffer fromConnection:(AVCaptureConnection *)connection originImageProcess:(BOOL)originImageProcess {
CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(inputSampleBuffer);
YTProcessOutput *output = [self.teBeautyKit processPixelData:pixelBuffer
pixelDataWidth:(int)CVPixelBufferGetWidth(pixelBuffer)
pixelDataHeight:(int)CVPixelBufferGetHeight(pixelBuffer)
withOrigin:YtLightImageOriginTopLeft
withOrientation:YtLightCameraRotation0];
if (output.pixelData.data != nil) {
/// 输出视频数据,渲染或者其他处理
}
if (output != nil) {
output.pixelData = nil;
output = nil;
}
}
3. 如需销毁,可参考如下
- (void)destroyXMagic {
[self.teBeautyKit onDestroy];
self.teBeautyKit = nil;
}

步骤五:导出美颜参数

支持在使用过程中实时导出美颜参数,需要在销毁前调用。
/// 导出
- (void)exportEffectData {
self.exportBeautyString = [self.teBeautyKit exportInUseSDKParam];
NSLog(@"%@",self.exportBeautyString);
[[NSUserDefaults standardUserDefaults] setObject:self.exportBeautyString forKey:kExportEffectData];
}
/// 设置
- (void)setExportEffectData {
self.exportBeautyString = [[NSUserDefaults standardUserDefaults] objectForKey:kExportEffectData];
if (self.exportBeautyString) {
[self.tePanelView setExportParamList:self.exportBeautyString];
}
}

附录

面板 JSON 文件说明

beauty_panel/
├── index.json ← 定义面板包含哪些 Tab
├── panel_json/ ← 定义每个 Tab 内的功能项
│ ├── beauty_template.json
│ ├── beauty.json
│ ├── beauty_image.json
│ ├── shape.json → beauty_base_shape.json / beauty_general_shape.json / beauty_shape.json
│ ├── beauty_body.json
│ ├── lut.json
│ ├── beauty_makeup.json
│ └── motions.json
└── panel_icon/ ← 面板所需的全部图标资源
详细请下载面板资源,并参考 README.md 文档

TEBeautyKit 方法说明

/// 创建TEBeautyKit对象
/// - Parameters:
/// - effectMode: EFFECT_MODE_NORMAL(高性能模式) EFFECT_MODE_PRO(默认模式)
/// 高性能模式开启后,美颜占用的系统 CPU/GPU 资源更少,可减少手机的发热和卡顿现象,更适合低端机长时间用。
/// 注意:开启高性能模式后,以下美颜项将不可用:
/// 1. 眼部:眼宽、眼高、祛眼袋
/// 2. 眉毛:角度、距离、高度、长度、粗细、眉峰
/// 3. 嘴部:微笑唇
/// 4. 面部:瘦脸(自然,女神,英俊),收下颌,祛皱、祛法令纹。建议用“脸型”实现综合大眼瘦脸效果
/// - onInitListener: 回调
+ (void)createXMagic:(EffectMode)effectMode onInitListener:(OnInitListener _Nullable)onInitListener;

/// 美颜鉴权
+ (void)setTELicense:(NSString *_Nullable)url key:(NSString *_Nullable)key completion:(callback _Nullable)completion;

/// 设置美颜对象
- (void)setXMagicApi:(XMagic *_Nullable)xmagicApi;

/// 设置renderSize
- (void)setRenderSize:(CGSize)size;

/// 设置图像方向
- (void)setImageOrientation:(YtLightDeviceCameraOrientation)orientation;

/// 获取当前GL上下文接口
- (nullable EAGLContext*)getCurrentGlContext;

/// 静音
- (void)setMute:(BOOL)isMute;

/// 开启能力
- (void)setFeatureEnableDisable:(NSString *_Nullable)featureName enable:(BOOL)enable;

/// 设置帧同步模式
/// isSync 是否是同步
/// syncFrameCount 同步的帧数。-1表示无限制。如果isSync为false,则此参数无意义
- (void)setSyncMode:(BOOL)isSync syncFrameCount:(int)syncFrameCount;

/// 获取设备等级
+ (DeviceLevel)getDeviceLevel;

/// 图片美颜
- (UIImage *_Nullable)processUIImage:(UIImage *_Nullable)inputImage
imageWidth:(int)imageWidth
imageHeight:(int)imageHeight
needReset:(bool)needReset;

/// 处理texture
/// - Parameters:
/// - textureId: 纹理id
/// - textureWidth: 纹理宽度
/// - textureHeight: 纹理高度
/// - origin: 枚举值,设置成YtLightImageOriginBottomLeft 时,图像上下镜像翻转
/// - orientation: 枚举值:图像旋转角度
- (YTProcessOutput *_Nullable)processTexture:(unsigned int)textureId
textureWidth:(int)textureWidth
textureHeight:(int)textureHeight
withOrigin:(YtLightImageOrigin)origin
withOrientation:(YtLightDeviceCameraOrientation)orientation;

/// 处理CVPixelBufferRef
/// - Parameters:
/// - pixelData: 图像数据
/// - pixelDataWidth: 图像宽度
/// - pixelDataHeight: 图像高度
/// - origin: 枚举值,设置成YtLightImageOriginBottomLeft 时,图像上下镜像翻转
/// - orientation: 枚举值:图像旋转角度
- (YTProcessOutput * _Nullable)processPixelData:(CVPixelBufferRef _Nullable )pixelData
pixelDataWidth:(int)pixelDataWidth
pixelDataHeight:(int)pixelDataHeight
withOrigin:(YtLightImageOrigin)origin
withOrientation:(YtLightDeviceCameraOrientation)orientation;

/// 设置美颜
- (void)setEffect:(TESDKParam *_Nullable)sdkParam;

/// 设置美颜
- (void)setEffectList:(NSArray<TESDKParam *>*_Nullable)sdkParamList;

/// 是否开启了美颜增强模式
- (BOOL)isEnableEnhancedMode;

/// 是否开启美颜增强模式
- (void)enableEnhancedMode:(BOOL)enable;

/// 恢复
- (void)onResume;

/// 暂停
- (void)onPause;

/// 销毁
- (void)onDestroy;

//获取当前texture的图片
- (void)exportCurrentTexture:(void (^_Nullable)(UIImage * _Nullable image))callback;

/// 设置log
- (void)registerSDKLogListener:(id<YTSDKLogListener> _Nullable)listener level:(YtSDKLoggerLevel)level;

/// SDK事件监听
- (void)registerSDKEventListener:(id<YTSDKEventListener> _Nullable)listener;

/// 保存设置的美颜数据
- (void)saveEffectParam:(TESDKParam *_Nonnull)sdkParam;

/// 删除某个保存的美颜数据
- (void)deleteEffectParam:(TESDKParam *_Nonnull)sdkParam;

/// 清空保存的美颜数据
- (void)clearEffectParam;

/// 设置输出纹理的居中裁剪比例
- (void)setOutputTextureKeepRatio:(float)ratio;

/// 获取保存的美颜数据
- (NSMutableArray<TESDKParam *> *_Nonnull)getInUseSDKParamList;

/// 导出正在使用的美颜数据
/// return json字符串
- (NSString *_Nullable)exportInUseSDKParam;

/// 设置美颜数据
/// - Parameter params: json字符串
/// 如果要同时设置面板UI,则只需要调用 TEPanelView 的 setExportParamList 即可
- (void)setExportedSDKParam:(NSString *_Nonnull)params;

/// 是否开启美颜
- (void)enableBeauty:(BOOL)enable;

/// 注册回调清理接口 Register callback cleanup interface
- (void)clearListeners;

TEUIConfig 说明

///可在外部修改下列属性的颜色
/// 美颜面板背景色
@property (nonatomic, strong) UIColor *panelBackgroundColor;
/// 分割线颜色
@property (nonatomic, strong) UIColor *panelDividerColor;
/// 选中项颜色
@property (nonatomic, strong) UIColor *panelItemCheckedColor;
/// 文本颜色
@property (nonatomic, strong) UIColor *textColor;
/// 文本选中颜色
@property (nonatomic, strong) UIColor *textCheckedColor;
/// 进度条颜色
@property (nonatomic, strong) UIColor *seekBarProgressColor;
/// 设置displayName展示的语言,默认YES:展示displayName字段,设置NO:展示displayNameEn字段
@property (nonatomic, assign) BOOL useDisplayName;
/// 面板布局方向,默认NO:LTR(从左到右),设置YES:RTL(从右到左,阿拉伯语等)
@property (nonatomic, assign) BOOL isLayoutRtl;
/// 面板文案name字段的匹配key(如zh/en/ja,客户可扩展其他key),不设置时使用defaultLanguage
@property (nonatomic, copy, nullable) NSString *displayNameKey;
/// 面板默认语言(index.json的defaultLanguage字段,SDK解析时自动写入,客户无需设置),key匹配失败时兜底
@property (nonatomic, copy, nullable) NSString *defaultLanguage;
/// 面板index.json文件路径(通过 setPanelViewRes:effectPlanName: 设置)
@property (nonatomic, copy, readonly, nullable) NSString *indexFilePath;
/// 当前套餐(通过 setPanelViewRes:effectPlanName: 设置)
@property (nonatomic, assign, readonly) TEEffectPlan effectPlan;
/// 单例
+ (instancetype)shareInstance;
/// 设置面板index.json路径和套餐
/// - Parameters:
/// - indexFilePath: index.json 文件路径
/// - effectPlan: 套餐类型
- (void)setPanelViewRes:(NSString *)indexFilePath effectPlanName:(TEEffectPlan)effectPlan;
/// 设置面板资源路径
/// - Parameter resources: 资源路径列表
/// e.g. @[@{TEUI_BEAUTY : @"json file path"}]
- (void)setTEPanelViewResources:(NSArray<NSDictionary *> *)resources;
/// 获取面板资源路径
- (NSArray<NSDictionary *> *)getTEPanelViewResources;
/// 设置LightCore.bundle路径
- (void)setLightCoreBundlePath:(NSString *)corePath;
/// 获取LightCore.bundle路径
- (NSString *)getLightCoreBundlePath;
/// 设置Resources bundle路径
- (void)setResourcesBundlePath:(NSString *)resPath;
/// 获取Resources bundle路径
- (NSString *)getResourcesBundlePath;

TEPanelView 说明

/// 美颜SDK对象
@property (nonatomic, weak) XMagic *beautyKitApi;
/// beautyKit对象
@property (nonatomic, strong) TEBeautyKit *teBeautyKit;
/// 代理
@property (nonatomic, weak) id<TEPanelViewDelegate> delegate;
/// 设置导出的美颜数据
- (void)setExportParamList:(NSString *)lastParamList;
/// 默认美颜
- (void)setDefaultBeauty;
/// 重置所有效果
- (void)performFullReset;
/// 增强模式
- (void)setEnhancedMode:(BOOL)enhancedMode;
/// 显示对比按钮
- (void)isShowCompareBtn:(BOOL)isShow;

设置多语言说明

面板的语言设置分为两部分:系统文本和面板项名称。
1. 系统文本
系统文本位于 Assets 下 Localizable.strings 文件中。
默认支持语言: 简体中文、英文。
添加其他语言:
在您的项目创建 Localizable.strings 文件,如果已经创建则只需添加其他语言即可。
在 PROJECT 列表中,Localizations 下面添加多语言。
翻译 TEBeautyKit 中的文本内容。
2. 面板项名称
4.4.0及之后版本
4.4.0之前版本
1. 在面板 json 文件中的 name 节点下添加对应的语言文本。
2. 代码中设置要显示对应语言的 key,例如要显示英文: [[TEUIConfig shareInstance] setDisplayNameKey:@"en"];
面板项名称定义在 JSON 配置文件中,通过以下两个字段控制:
字段
默认语言
displayName
简体中文
displayNameEn
英文
切换中英文:
// 显示中文(使用 displayName 字段)
[[TEUIConfig shareInstance] setUseDisplayName:YES];
// 显示英文(使用 displayNameEn 字段)
[[TEUIConfig shareInstance] setUseDisplayName:NO];
添加其他语言:
复制原 JSON 文件,创建对应语言的版本(如繁体中文 panel_zh_hant.json)。
将 displayName 字段的值翻译为目标语言。
在代码中检测当前系统语言,加载对应的 JSON 文件。
调用 [[TEUIConfig shareInstance] setUseDisplayName:YES]。


帮助和支持

本页内容是否解决了您的问题?

填写满意度调查问卷,共创更好文档体验。

文档反馈