【无标题】

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
                
        self.headerImageView = [[UIImageView alloc] initWithFrame:CGRectMake(17*BiLiWidth, 16*BiLiWidth, 76*BiLiWidth, 76*BiLiWidth)];
        self.headerImageView.contentMode = UIViewContentModeScaleAspectFill;
        self.headerImageView.autoresizingMask = UIViewAutoresizingNone;
        self.headerImageView.clipsToBounds = YES;
        self.headerImageView.layer.cornerRadius = 76*BiLiWidth/2;
        [self.contentView addSubview:self.headerImageView];
        
    }
    return self;
}
    NSDictionary *headers = @{@"Content-Type": @"application/json"};
    NSData *data = UIImagePNGRepresentation(self.originImage);
    NSString * imageBase64Str = [data base64EncodedStringWithOptions:0];
    NSDictionary * info = @{@"width":[NSNumber numberWithInt:100],@"top":[NSNumber numberWithInt:0],@"height":[NSNumber numberWithInt:100],@"left":[NSNumber numberWithInt:0]};
    NSArray * rectangleArray = [[NSArray alloc] initWithObjects:info, nil];
    //处理好的参数
    NSDictionary * postDic = @{@"image":imageBase64Str,@"rectangle":rectangleArray};
    
    NSData *postData = [NSJSONSerialization dataWithJSONObject:postDic options:0 error:nil];

    NSDictionary * tokenInfo = [GongJvManger getDefaultsObjectKey:ApiInfoDefaults];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@?access_token=%@",@"https://aip.baidubce.com/rest/2.0/image-process/v1/inpainting",[tokenInfo objectForKey:@"access_token"]]]
                                                           cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                       timeoutInterval:10.0];
    [request setHTTPMethod:@"POST"];
    [request setAllHTTPHeaderFields:headers];
    [request setHTTPBody:postData];
    NSURLSession *session = [NSURLSession sharedSession];
    NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
                                                completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {

        dispatch_async(dispatch_get_main_queue(), ^{

            [WSProgressHUD dismiss];
            if (error) {
                [WSProgressHUD showErrorWithStatus:error.localizedDescription];
            } else {

                NSDictionary * dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
                if ([[dict allKeys] containsObject:@"error_code"]) {
                    
                    NSNumber * errorCode = [dict objectForKey:@"error_code"];
                    if (errorCode.intValue==110||errorCode.intValue==111) {
                        
                        [NetWorkModel getApiToken:@{@"grant_type":@"client_credentials",@"client_id":client_id,@"client_secret":client_secret} callback:^(NSInteger status, id  _Nullable responseObject, NSString * _Nullable msg) {
                            
                            [GongJvManger setDefaultsObject:responseObject forKey:ApiInfoDefaults];
                        }];
                    }
                    [WSProgressHUD showErrorWithStatus:[dict objectForKey:@"error_msg"]];
                }
                else
                {
                    NSString * base64Str = [dict objectForKey:@"image"];
                    NSData * showData = [[NSData alloc]initWithBase64EncodedString:base64Str options:NSDataBase64DecodingIgnoreUnknownCharacters];
                    
                    [self setFinishResultImage:[UIImage imageWithData:showData]];

                }

            }
        });

    }];
    [dataTask resume];

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

义中

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值