#import "AppDelegate.h"
#import "FaceppAPI.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
//037607e4343a265a543fbdedf4e990a8
//5pJpREsJkEDHBG_MOtiMNaa9NSgdPGW3
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[FaceppAPIinitWithApiKey:@"037607e4343a265a543fbdedf4e990a8"andApiSecret:@"5pJpREsJkEDHBG_MOtiMNaa9NSgdPGW3"
andRegion:APIServerRegionCN];
[FaceppAPIsetDebugMode:YES];
return YES;
}
#import "ViewController.h"
#import "FaceppAPI.h"
@interface ViewController ()
//037607e4343a265a543fbdedf4e990a8
//5pJpREsJkEDHBG_MOtiMNaa9NSgdPGW3
@end
@implementation ViewController
- (IBAction)oneChangeImage:(id)sender {
//1.创建一个图片
NSData *imageData =UIImageJPEGRepresentation(
[UIImageimageNamed:@"少女时代.png"],100);
//2.开始解析
FaceppResult *result = [[FaceppAPIdetection] detectWithURL:nil
orImageData:imageData];
//需求 是 找到右边那张脸 替换一下
//所有脸的字典信息
NSArray *allFaces = result.content[@"face"];
NSDictionary *dict = [allFaces lastObject];
//脸的 x y W H
// 60 像素 60/100 * 320 像素
NSDictionary *position = dict[@"position"];
CGFloat faceW = [position[@"width"]floatValue] * 0.01 *self.view.bounds.size.width;
CGFloat faceH = [position[@"height"] floatValue] *0.01 * self.view.bounds.size.height;
CGFloat faceX = ([position[@"center"][@"x"] floatValue] - [position[@"width"] floatValue] *0.5 )* 0.01 *self.view.bounds.size.width;
CGFloat faceY = ([position[@"center"][@"y"] floatValue] - [position[@"height"] floatValue] *0.5)* 0.01 *self.view.bounds.size.height;
NSLog(@"%f %f %f %f",faceX , faceY,faceW,faceH);
CGRect rect = CGRectMake(faceX - 65, faceY -25, faceW + 50, faceH +100);
UIGraphicsBeginImageContext(self.imageView.bounds.size);
//绘制原图
[self.imageView.image drawAtPoint:CGPointMake(0,0)];
//绘制新图
UIImage *newimage = [UIImage imageNamed:@"xiaocang"];
[newimage drawInRect:rect];
//设置新图
UIImage *resultImage = UIGraphicsGetImageFromCurrentImageContext();
self.imageView.image = resultImage;
UIGraphicsEndImageContext();
NSLog(@"%@",result);
}
- (void)viewDidLoad {
[super viewDidLoad];
//face++
self.imageView.image = [UIImage imageNamed:@"少女时代.png"];
}
@end