圖片選擇庫TZImagePickerController用法

#import <TZImagePickerController.h>

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

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

? ? // 你可以通過block或者代理,來得到用戶選擇的照片.

? ? [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *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;

}

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容