iOS TZImagePickerController使用
#pragma TZImagePickerController
- (void)setTZimageView
{
TZImagePickerController *imagePC = [[TZImagePickerController alloc]initWithMaxImagesCount:1 delegate:self];
// imagePC.iconThemeColor = UIColor.redColor;
imagePC.naviBgColor = AppMainColor;
imagePC.oKButtonTitleColorNormal = AppMainColor;
// imagePC.oKButtonTitleColorDisabled = UIColor.purpleColor;
imagePC.allowTakePicture = YES;
imagePC.allowTakeVideo = NO;
imagePC.allowPickingVideo = NO;
imagePC.allowPickingGif = NO;
imagePC.showSelectedIndex = YES;
// imagePC.showSelectBtn = YES;
imagePC.allowPickingOriginalPhoto = YES;//原图
imagePC.minImagesCount = 0;
imagePC.maxImagesCount = 1;
imagePC.showSelectBtn = NO;
imagePC.allowPreview = YES;
// imagePC.allowCrop = YES; //YES和NO不影响选择视频 但是视频也不能裁剪
// imagePC.needCircleCrop = NO;//是否是圆形裁剪 YES 则是圆形裁剪 NO 方形
// imagePC.cropRect = CGRectMake(0, (HEIGHT_SCREEN - WIDTH_SCREEN)/2, WIDTH_SCREEN, WIDTH_SCREEN);
imagePC.autoSelectCurrentWhenDone = YES;
imagePC.modalPresentationStyle = 0;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self presentViewController:imagePC animated:YES completion:nil];
});
}
- (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingPhotos:(NSArray<UIImage *> *)photos sourceAssets:(NSArray *)assets isSelectOriginalPhoto:(BOOL)isSelectOriginalPhoto{
_imageBtn.hidden = YES;//隐藏添加图片按钮
self.deleteImgBtn.hidden = NO;//显示删除照片按钮
self.imageView.backgroundColor = UIColor.clearColor;
for (UIImage *img in photos) {
[_imageView setImage:img];
self.noteImg = img;
}
}
//上传图片至服务器后台
- (void)transportImgToServerWithImg:(UIImage *)img{
NSData *imageData;
NSString *mimetype;
//判断下图片是什么格式
if (UIImagePNGRepresentation(img) != nil) {
mimetype = @"image/png";
imageData = UIImagePNGRepresentation(img);
}else{
mimetype = @"image/jpeg";
imageData = UIImageJPEGRepresentation(img, 1.0);
}
AFHTTPSessionManager * manager = [[AFHTTPSessionManager alloc]init];
NSDictionary *parameters = @{
@"sid":@"71859f86881f4f9683a003307c7d2f66"
};
NSLog(@"url==%@",PostUploadImage);
[manager POST:PostUploadImage parameters:parameters headers:nil constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
NSString *str = @"logoFile";
NSString *fileName = [[NSString alloc] init];
if (UIImagePNGRepresentation(img) != nil) {
fileName = [NSString stringWithFormat:@"%@_noteImg.png", [UserInfo getHDZUserID]];
}else{
fileName = [NSString stringWithFormat:@"%@_noteImg.jpeg", [UserInfo getHDZUserID]];
}
[formData appendPartWithFileData:imageData name:str fileName:fileName mimeType:mimetype];
} progress:^(NSProgress * _Nonnull uploadProgress) {
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSLog(@"responseObject打印结果 : %@",responseObject);
BOOL isSuccess = responseObject[@"success"];
if (isSuccess == YES) {
self.imgPath = responseObject[@"imgPath"];
[self requestNetWorkMethod];
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"error : %@", error);
}];
}