图片选择库TZImagePickerController用法

#import

TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:1 delegate:self];

    // You can get the photos by block, the same as by delegate.

    // 你可以通过block或者代理,来得到用户选择的照片.

    [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {

        NSData * imagedata=UIImageJPEGRepresentation(photos[0], 1);

        NSInteger  length = imagedata.length/1024;


        NSString *dataLength = [self getBytesFromDataLength:imagedata.length];

        NSLog(@"原来图片的大小是%ldkb",length);


        NSLog(@"原来图片的大小是%@",dataLength);


    }];


    [self presentViewController:imagePickerVc animated:YES completion:nil];

//计算图片大小

- (NSString *)getBytesFromDataLength:(NSInteger)dataLength {

    NSString *bytes;

    if (dataLength >= 0.1 * (1024 * 1024)) {

        bytes = [NSString stringWithFormat:@"%0.1fM",dataLength/1024/1024.0];

    } else if (dataLength >= 1024) {

        bytes = [NSString stringWithFormat:@"%0.0fK",dataLength/1024.0];

    } else {

        bytes = [NSString stringWithFormat:@"%zdB",dataLength];

    }

    return bytes;

}

你可能感兴趣的:(图片选择库TZImagePickerController用法)