Commit 8d842b39 authored by yuzheng.tz's avatar yuzheng.tz

整理代码

parent b669edf9
......@@ -106,6 +106,9 @@
/// 获取asset的资源类型
- (TZAssetModelMediaType)getAssetType:(id)asset;
/// 缩放图片至新尺寸
- (UIImage *)scaleImage:(UIImage *)image toSize:(CGSize)size;
@end
//@interface TZSortDescriptor : NSSortDescriptor
......
......@@ -921,6 +921,7 @@ static dispatch_once_t onceToken;
return model;
}
/// 缩放图片至新尺寸
- (UIImage *)scaleImage:(UIImage *)image toSize:(CGSize)size {
if (image.size.width > size.width) {
UIGraphicsBeginImageContext(size);
......@@ -928,6 +929,19 @@ static dispatch_once_t onceToken;
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
/* 好像不怎么管用:https://mp.weixin.qq.com/s/CiqMlEIp1Ir2EJSDGgMooQ
CGFloat maxPixelSize = MAX(size.width, size.height);
CGImageSourceRef sourceRef = CGImageSourceCreateWithData((__bridge CFDataRef)UIImageJPEGRepresentation(image, 0.9), nil);
NSDictionary *options = @{(__bridge id)kCGImageSourceCreateThumbnailFromImageAlways:(__bridge id)kCFBooleanTrue,
(__bridge id)kCGImageSourceThumbnailMaxPixelSize:[NSNumber numberWithFloat:maxPixelSize]
};
CGImageRef imageRef = CGImageSourceCreateImageAtIndex(sourceRef, 0, (__bridge CFDictionaryRef)options);
UIImage *newImage = [UIImage imageWithCGImage:imageRef scale:2 orientation:image.imageOrientation];
CGImageRelease(imageRef);
CFRelease(sourceRef);
return newImage;
*/
} else {
return image;
}
......
......@@ -373,7 +373,7 @@ static CGFloat itemMargin = 5;
[[TZImageManager manager] getPhotoWithAsset:model.asset completion:^(UIImage *photo, NSDictionary *info, BOOL isDegraded) {
if (isDegraded) return;
if (photo) {
photo = [self scaleImage:photo toSize:CGSizeMake(tzImagePickerVc.photoWidth, (int)(tzImagePickerVc.photoWidth * photo.size.height / photo.size.width))];
photo = [[TZImageManager manager] scaleImage:photo toSize:CGSizeMake(tzImagePickerVc.photoWidth, (int)(tzImagePickerVc.photoWidth * photo.size.height / photo.size.width))];
[photos replaceObjectAtIndex:i withObject:photo];
}
if (info) [infoArr replaceObjectAtIndex:i withObject:info];
......@@ -662,18 +662,6 @@ static CGFloat itemMargin = 5;
}];
}
/// Scale image / 缩放图片
- (UIImage *)scaleImage:(UIImage *)image toSize:(CGSize)size {
if (image.size.width < size.width) {
return image;
}
UIGraphicsBeginImageContext(size);
[image drawInRect:CGRectMake(0, 0, size.width, size.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
- (void)scrollCollectionViewToBottom {
TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController;
if (_shouldScrollToBottom && _models.count > 0) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment