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.

This commit is contained in:
Guillaume BIENKOWSKI 2014-05-23 09:30:42 +02:00
parent 5ae6a6ac73
commit 4fca20ef30
2 changed files with 12 additions and 7 deletions

View file

@ -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];
}
}
}

View file

@ -18,6 +18,8 @@
*/
#import <UIKit/UIKit.h>
#import <AssetsLibrary/ALAsset.h>
#import <AssetsLibrary/ALAssetRepresentation.h>
@interface UILoadingImageView : UIImageView
@ -26,6 +28,7 @@
- (BOOL)isLoading;
- (void)stopLoading;
@property (nonatomic, retain) ALAsset* fullImageUrl;
@property (nonatomic, readonly) IBOutlet UIActivityIndicatorView *waitIndicatorView;
@end