From 4fca20ef30557d291d348b7ae592ae457397c87d Mon Sep 17 00:00:00 2001 From: Guillaume BIENKOWSKI Date: Fri, 23 May 2014 09:30:42 +0200 Subject: [PATCH] Change how we handle image display in chatroom: the old method would lead to strange leaks. This one uses the asset's facilities to grab a thumbnail and display it instead of generating a scaled version of the full res image. --- Classes/LinphoneUI/UIChatRoomCell.m | 16 +++++++++------- Classes/LinphoneUI/UILoadingImageView.h | 3 +++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Classes/LinphoneUI/UIChatRoomCell.m b/Classes/LinphoneUI/UIChatRoomCell.m index 0320d9042..3bc0b6d71 100644 --- a/Classes/LinphoneUI/UIChatRoomCell.m +++ b/Classes/LinphoneUI/UIChatRoomCell.m @@ -127,21 +127,21 @@ static UIFont *CELL_FONT = nil; } else if(url) { + NSURL* imageUrl = [NSURL URLWithString:[NSString stringWithUTF8String:url]]; + [messageText setHidden:TRUE]; [messageImageView setImage:nil]; [messageImageView startLoading]; __block LinphoneChatMessage *achat = chat; - [[LinphoneManager instance].photoLibrary assetForURL:[NSURL URLWithString:[NSString stringWithUTF8String:url]] resultBlock:^(ALAsset *asset) { + [[LinphoneManager instance].photoLibrary assetForURL:imageUrl resultBlock:^(ALAsset *asset) { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, (unsigned long)NULL), ^(void) { - ALAssetRepresentation* representation = [asset defaultRepresentation]; - UIImage *image = [UIImage imageWithCGImage:[representation fullResolutionImage] - scale:representation.scale - orientation:(UIImageOrientation)representation.orientation]; - image = [UIImage decodedImageWithImage:image]; + UIImage* image = [[UIImage alloc] initWithCGImage:[asset thumbnail]]; if(achat == self->chat) { //Avoid glitch and scrolling dispatch_async(dispatch_get_main_queue(), ^{ [messageImageView setImage:image]; + [messageImageView setFullImageUrl:asset]; [messageImageView stopLoading]; + [image release]; }); } }); @@ -313,7 +313,9 @@ static UIFont *CELL_FONT = nil; if(![messageImageView isLoading]) { ImageViewController *controller = DYNAMIC_CAST([[PhoneMainView instance] changeCurrentView:[ImageViewController compositeViewDescription] push:TRUE], ImageViewController); if(controller != nil) { - [controller setImage:messageImageView.image]; + CGImageRef fullScreenRef = [[messageImageView.fullImageUrl defaultRepresentation] fullScreenImage]; + UIImage* fullScreen = [UIImage imageWithCGImage:fullScreenRef]; + [controller setImage:fullScreen]; } } } diff --git a/Classes/LinphoneUI/UILoadingImageView.h b/Classes/LinphoneUI/UILoadingImageView.h index a27c7462d..5fcfe2f7e 100644 --- a/Classes/LinphoneUI/UILoadingImageView.h +++ b/Classes/LinphoneUI/UILoadingImageView.h @@ -18,6 +18,8 @@ */ #import +#import +#import @interface UILoadingImageView : UIImageView @@ -26,6 +28,7 @@ - (BOOL)isLoading; - (void)stopLoading; +@property (nonatomic, retain) ALAsset* fullImageUrl; @property (nonatomic, readonly) IBOutlet UIActivityIndicatorView *waitIndicatorView; @end