From f4841da4ebaac519e10d8c91faaeca547de5944a Mon Sep 17 00:00:00 2001 From: Benjamin Verdier Date: Thu, 14 Jun 2018 16:24:43 +0200 Subject: [PATCH] Fix the images being squeezed --- Classes/LinphoneUI/UIChatBubblePhotoCell.m | 5 ++++- Classes/LinphoneUI/UIChatBubbleTextCell.m | 10 +++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Classes/LinphoneUI/UIChatBubblePhotoCell.m b/Classes/LinphoneUI/UIChatBubblePhotoCell.m index 0e138836d..55ae42a0f 100644 --- a/Classes/LinphoneUI/UIChatBubblePhotoCell.m +++ b/Classes/LinphoneUI/UIChatBubblePhotoCell.m @@ -340,15 +340,18 @@ - (CGImageRef)cropImageFromRepresentation:(ALAssetRepresentation*)rep { CGImageRef newImage = [rep fullResolutionImage]; CGSize originalSize = [rep dimensions]; + float originalAspectRatio = originalSize.width / originalSize.height; // We resize in width and crop in height if (originalSize.width > imageSize.width) { - int height = originalSize.height * imageSize.width / originalSize.width; + int height = imageSize.width / originalAspectRatio; newImage = [self.class resizeCGImage:newImage toWidth:imageSize.width andHeight:height]; originalSize.height = height; } CGRect cropRect = CGRectMake(0, 0, imageSize.width, imageSize.height); if (imageSize.height < originalSize.height) cropRect.origin.y = (originalSize.height - imageSize.height)/2; newImage = CGImageCreateWithImageInRect(newImage, cropRect); + LOGD([NSString stringWithFormat:@"Image size : width = %g, height = %g", imageSize.width, imageSize.height]); + LOGD([NSString stringWithFormat:@"Bubble size : width = %g, height = %g", super.bubbleView.frame.size.width, super.bubbleView.frame.size.height]); return newImage; } diff --git a/Classes/LinphoneUI/UIChatBubbleTextCell.m b/Classes/LinphoneUI/UIChatBubbleTextCell.m index 235c1f0a9..f31b4e080 100644 --- a/Classes/LinphoneUI/UIChatBubbleTextCell.m +++ b/Classes/LinphoneUI/UIChatBubbleTextCell.m @@ -343,6 +343,8 @@ static const CGFloat CELL_MESSAGE_Y_MARGIN = 52; // 44; dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER); size = [self getMediaMessageSizefromOriginalSize:originalImageSize withWidth:width]; + //This fixes the image being too small. I think the issue comes form the fact that the display is retina. This should probably be changed in the future. + size.height += CELL_MESSAGE_Y_MARGIN; } size.width = MAX(size.width + CELL_MESSAGE_X_MARGIN, CELL_MIN_WIDTH); size.height = MAX(size.height + CELL_MESSAGE_Y_MARGIN, CELL_MIN_HEIGHT); @@ -396,11 +398,13 @@ static const CGFloat CELL_MESSAGE_Y_MARGIN = 52; // 44; if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) { availableWidth = availableWidth /3; } - int height = originalSize.height; + int newHeight = originalSize.height; + float originalAspectRatio = originalSize.width / originalSize.height; + // We resize in width and crop in height if (originalSize.width > availableWidth) { - height = originalSize.height * availableWidth / originalSize.width; + newHeight = availableWidth / originalAspectRatio; } - mediaSize.height = MIN(height, availableWidth); + mediaSize.height = MIN(newHeight, availableWidth); mediaSize.width = MIN(availableWidth, originalSize.width); return mediaSize; }