码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-03-13 14:23:50      阅读:741      评论:0      收藏:0      [点我收藏+]

标签:pat   init   需要   选项   selector   normal   result   send   input   

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 
 
 
 

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

标签:pat   init   需要   选项   selector   normal   result   send   input   

原文地址:http://www.cnblogs.com/firstrate/p/6542249.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!