mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-27 07:59:20 +00:00
moved resizeImage method to utils
This commit is contained in:
parent
5b6e9f6edb
commit
48f717f0ae
5 changed files with 32 additions and 36 deletions
|
|
@ -167,39 +167,6 @@
|
|||
}
|
||||
}
|
||||
|
||||
+ (UIImage *)resizeImage:(UIImage *)image
|
||||
{
|
||||
float actualHeight = image.size.height;
|
||||
float actualWidth = image.size.width;
|
||||
float maxHeight = 200.0;
|
||||
float maxWidth = 200.0;
|
||||
float imgRatio = actualWidth/actualHeight;
|
||||
float maxRatio = maxWidth/maxHeight;
|
||||
float compressionQuality = 1;
|
||||
if (actualHeight > maxHeight || actualWidth > maxWidth)
|
||||
{
|
||||
if(imgRatio < maxRatio) {
|
||||
imgRatio = maxHeight / actualHeight;
|
||||
actualWidth = imgRatio * actualWidth;
|
||||
actualHeight = maxHeight;
|
||||
} else if(imgRatio > maxRatio) {
|
||||
imgRatio = maxWidth / actualWidth;
|
||||
actualHeight = imgRatio * actualHeight;
|
||||
actualWidth = maxWidth;
|
||||
} else {
|
||||
actualHeight = maxHeight;
|
||||
actualWidth = maxWidth;
|
||||
}
|
||||
}
|
||||
CGRect rect = CGRectMake(0.0, 0.0, actualWidth, actualHeight);
|
||||
UIGraphicsBeginImageContext(rect.size);
|
||||
[image drawInRect:rect];
|
||||
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
|
||||
NSData *imageData = UIImageJPEGRepresentation(img, compressionQuality);
|
||||
UIGraphicsEndImageContext();
|
||||
return [UIImage imageWithData:imageData];
|
||||
}
|
||||
|
||||
+ (void) saveDataToUserDefaults {
|
||||
const bctbx_list_t *logs = linphone_core_get_call_logs(LC);
|
||||
NSUserDefaults *mySharedDefaults = [[NSUserDefaults alloc] initWithSuiteName: @"group.belledonne-communications.linphone.widget"];
|
||||
|
|
@ -215,7 +182,7 @@
|
|||
//FastAddressBook *fab = [LinphoneManager instance].fastAddressBook;
|
||||
Contact * contact = [FastAddressBook getContactWithAddress:linphone_call_log_get_remote_address(log)];
|
||||
if (contact && contact.avatar) {
|
||||
UIImage *image = [self resizeImage:contact.avatar];
|
||||
UIImage *image = [UIImage resizeImage:contact.avatar withMaxWidth:200 andMaxHeight:200];
|
||||
NSData *imageData = UIImageJPEGRepresentation(image, 0);
|
||||
[images setObject:imageData
|
||||
forKey:[[NSString stringWithUTF8String:linphone_address_as_string_uri_only(linphone_call_log_get_remote_address(log))] substringFromIndex:4]];
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ typedef enum {
|
|||
|
||||
- (UIImage *)squareCrop;
|
||||
- (UIImage *)scaleToSize:(CGSize)size squared:(BOOL)squared;
|
||||
+ (UIImage *)resizeImage:(UIImage *)image withMaxWidth:(float)maxWidth andMaxHeight:(float)maxHeight;
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
|||
|
|
@ -644,6 +644,36 @@
|
|||
return scaledImage;
|
||||
}
|
||||
|
||||
+ (UIImage *)resizeImage:(UIImage *)image withMaxWidth:(float)maxWidth andMaxHeight:(float)maxHeight {
|
||||
float actualHeight = image.size.height;
|
||||
float actualWidth = image.size.width;
|
||||
float imgRatio = actualWidth / actualHeight;
|
||||
float maxRatio = maxWidth / maxHeight;
|
||||
float compressionQuality = 1;
|
||||
if (actualHeight > maxHeight || actualWidth > maxWidth)
|
||||
{
|
||||
if (imgRatio < maxRatio) {
|
||||
imgRatio = maxHeight / actualHeight;
|
||||
actualWidth = imgRatio * actualWidth;
|
||||
actualHeight = maxHeight;
|
||||
} else if (imgRatio > maxRatio) {
|
||||
imgRatio = maxWidth / actualWidth;
|
||||
actualHeight = imgRatio * actualHeight;
|
||||
actualWidth = maxWidth;
|
||||
} else {
|
||||
actualHeight = maxHeight;
|
||||
actualWidth = maxWidth;
|
||||
}
|
||||
}
|
||||
CGRect rect = CGRectMake(0.0, 0.0, actualWidth, actualHeight);
|
||||
UIGraphicsBeginImageContext(rect.size);
|
||||
[image drawInRect:rect];
|
||||
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
|
||||
NSData *imageData = UIImageJPEGRepresentation(img, compressionQuality);
|
||||
UIGraphicsEndImageContext();
|
||||
return [UIImage imageWithData:imageData];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation UIColor (LightAndDark)
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@
|
|||
@property (strong, nonatomic) NSMutableDictionary *imgs;
|
||||
@property (strong, nonatomic) NSMutableArray *sortedDates;
|
||||
@property (strong, nonatomic) NSMutableArray *logIds;
|
||||
@property (nonatomic) BOOL updateNeeded;
|
||||
|
||||
- (IBAction)firstButtonTapped;
|
||||
- (IBAction)secondButtonTapped;
|
||||
|
|
|
|||
|
|
@ -131,7 +131,6 @@
|
|||
_sortedDates = [NSMutableArray array];
|
||||
_contactsToDisplay = [NSMutableArray array];
|
||||
_imgs = [NSMutableDictionary dictionary];
|
||||
_updateNeeded = YES;
|
||||
}
|
||||
|
||||
- (void)didReceiveMemoryWarning {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue