• TuSDK 简易使用方法 持有图片对象方式


    TuSDK 为涂图照相应用的SDK,打包后文件大小约为5M,缺点为包比较大,且图片清晰度较差一些,优点为直接可以引用滤镜贴纸,方便易用。
     
    使用方法如下: 
     
    1.AppDelegate.m 中加入如下代码行:
     
        [TuSDKinitSdkWithAppKey:@"20411a706f17b358-00-8y5nq1”];
     
    记载tuSDK App 应用的key
     
     
    2.ViewController 中加入如下代码行:
     
    声明方法:
     
    继承:
     
    @interface ViewController : TuSDKICViewController
     
    声明变量
     
    @interfaceViewController ()<TuSDKFilterManagerDelegate>
    {
       
    CameraAndEditorSample *cameraComponentSample;
       
    EditMultipleComponentSample *editcomponent;
    }

    声明中先声明两个对象  CameraAndEditorSample 和 EditMultipleComponentSample
     
     
        [selfshowHubWithStatus:LSQString(@"lsq_initing", @"正在初始化")];
        [
    TuSDKcheckManagerWithDelegate:self];
       
    NSLog(@"版本号 : %@",lsqSDKVersion);
     
    初始化TuSDK 方法 
     
    - (void)onTuSDKFilterManagerInited:(TuSDKFilterManager *)manager
    {
        [
    selfshowHubSuccessWithStatus:LSQString(@"lsq_inited", @"初始化完成")];
    }
     
    初始化完成调用如上方法
     
    - (IBAction)actionCamera:(UIButton *)btn {
       
    if(cameraComponentSample == nil) {
           
    cameraComponentSample = [CameraAndEditorSamplesample];
        }
        [
    cameraComponentSampleshowSampleWithController:self];
    }

    - (
    IBAction)actionPhoto:(UIButton *)sender {

       
    if (editcomponent == nil)
           
    editcomponent = [EditMultipleComponentSamplesample];
        [
    editcomponentshowSampleWithController:self];
    }
     
    调用如上命令行来应用此方法
     
     
     
    3. CameraAndEditorSample.h 文件中持有处理后图片方法 :
     
     
     
    - (void)openEditMultipleWithController:(UIViewController *)controller
                                    result:(
    TuSDKResult *)result;
    {
       
    if (!controller || !result) return;
       
       
    // 组件选项配置
       
    // @see-https://tusdk.com/docs/ios/api-gee/Classes/TuSDKCPPhotoEditMultipleComponent.html
       
    _photoEditMultipleComponent =
        [
    TuSDKGeeV1photoEditMultipleWithController:controller
                                     
    callbackBlock:^(TuSDKResult *result, NSError *error, UIViewController *controller)
         {
            
            
    // 如果以 pushViewController 方式打开编辑器, autoDismissWhenCompelted参数将无效, 请使用以下方法关闭
            
    //if (_photoEditMultipleComponent.autoDismissWhenCompelted && controller) {
            
    //    [controller popViewControllerAnimated:YES];
            
    //}
            
            
    // 获取图片失败
            
    if (error) {
                
    lsqLError(@"editMultiple error: %@", error.userInfo);
                
    return;
             }
             [result
    logInfo];
            
    //[self openEditorWithImage:result.image];
            
    // 可在此添加自定义方法,将result结果传出,例如  [self openEditorWithImage:result.image];
            
    // 并在外部使用方法接收result结果,例如 -(void)openEditorWithImage:(UIImage *)image;
         }];
        [
    selfopenEditorWithImage:result.image]; //持有图片方法
       
    // 设置图片
       
    _photoEditMultipleComponent.inputImage = result.image;
       
    _photoEditMultipleComponent.inputTempFilePath = result.imagePath;
       
    _photoEditMultipleComponent.inputAsset = result.imageAsset;
       
    // 是否在组件执行完成后自动关闭组件 (默认:NO)
       
    _photoEditMultipleComponent.autoDismissWhenCompelted = YES;
       
    // 当上一个页面是NavigationController,是否通过 pushViewController 方式打开编辑器视图 (默认:NO,默认以 presentViewController 方式打开)
       
    // SDK 内部组件采用了一致的界面设计,会通过 push 方式打开视图。如果用户开启了该选项,在调用时可能会遇到布局不兼容问题,请谨慎处理。
       
    _photoEditMultipleComponent.autoPushViewController = YES;
        [
    _photoEditMultipleComponentshowComponent];
    }
     
    -(void)openEditorWithImage:(UIImage *)image
    {
       
    NSLog(@"Finalimage = %@", image);
        [[
    NSNotificationCenterdefaultCenter] postNotificationName:@"imagePost"object:image];
    }
     
     
    通过通知方法来告知其他模块来持有处理后的图片,进行显示出来
     
     
    然后在需要用到图片的地方调用此通知:
     
    [[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(getPhoto:) name:@"imagePost"object:nil];
     
     
    - (void)getPhoto:(NSNotification *)sender
    {
       
    _imageView.image = sender.object;
       
    NSLog(@"sender : %@",sender);
    }

     
    便可以拿到此图片对象 sender.object 
     
     
     
  • 相关阅读:
    拷贝构造函数与赋值函数的区别
    C++模板(一)
    拷贝构造函数
    memcpy函数
    malloc calloc 和 realloc
    extern关键字
    C中不安全函数
    缓冲区溢出问题
    C++引用
    背包问题专栏(01,完全,多重)
  • 原文地址:https://www.cnblogs.com/firstrate/p/6542249.html
Copyright © 2020-2023  润新知