mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +00:00
Support loading animated images from the local filesystem
This commit is contained in:
@@ -457,15 +457,27 @@ static const CGSize kMinReleaseImageOnBackgroundSize = {20.0, 20.0};
|
||||
} else {
|
||||
// First try to load the path directly, for efficiency assuming a developer who
|
||||
// doesn't want caching is trying to be as minimal as possible.
|
||||
self.image = [UIImage imageWithContentsOfFile:_URL.path];
|
||||
if (!self.image) {
|
||||
NSData *data = [NSData dataWithContentsOfURL:_URL];
|
||||
if (data == nil) {
|
||||
// If we couldn't find it, execute an -imageNamed:-like search so we can find resources even if the
|
||||
// extension is not provided in the path. This allows the same path to work regardless of shouldCacheImage.
|
||||
NSString *filename = [[NSBundle mainBundle] pathForResource:_URL.path.lastPathComponent ofType:nil];
|
||||
if (filename) {
|
||||
self.image = [UIImage imageWithContentsOfFile:filename];
|
||||
if (filename != nil) {
|
||||
data = [NSData dataWithContentsOfFile:filename];
|
||||
}
|
||||
}
|
||||
|
||||
// If the file may be an animated gif and then created an animated image.
|
||||
id<ASAnimatedImageProtocol> animatedImage = nil;
|
||||
if (_downloaderImplementsAnimatedImage && data != nil && [_URL.pathExtension isEqualToString:@"gif"]) {
|
||||
animatedImage = [_downloader animatedImageWithData:data];
|
||||
}
|
||||
|
||||
if (animatedImage != nil) {
|
||||
self.animatedImage = animatedImage;
|
||||
} else {
|
||||
self.image = [UIImage imageWithData:data];
|
||||
}
|
||||
}
|
||||
|
||||
_imageLoaded = YES;
|
||||
|
||||
Reference in New Issue
Block a user