diff --git a/Classes/ArtworkViewController.m b/Classes/ArtworkViewController.m index 3b55d7e..d5730ba 100644 --- a/Classes/ArtworkViewController.m +++ b/Classes/ArtworkViewController.m @@ -29,9 +29,8 @@ return [systemFrameworksPath stringByDeletingLastPathComponent]; } -static NSString *pathWithScale(NSString *path) +static NSString *pathWithScale(NSString *path, CGFloat scale) { - CGFloat scale = [[UIScreen mainScreen] scale]; if (scale > 1) return [[[path stringByDeletingPathExtension] stringByAppendingFormat:@"@%gx", scale] stringByAppendingPathExtension:[path pathExtension]]; else @@ -41,9 +40,11 @@ // Workaround http://www.openradar.me/8225750 static UIImage *imageWithContentsOfFile(NSString *path) { - if ([[NSFileManager defaultManager] fileExistsAtPath:pathWithScale(path)]) - path = pathWithScale(path); - return [UIImage imageWithContentsOfFile:path]; + NSString *imagePathWithScale = pathWithScale(path, [[UIScreen mainScreen] scale]); + if ([[NSFileManager defaultManager] fileExistsAtPath:imagePathWithScale]) + return [UIImage imageWithContentsOfFile:imagePathWithScale]; + else + return [UIImage imageWithContentsOfFile:path]; } @@ -244,9 +245,10 @@ - (void) saveImage:(NSDictionary *)imageInfo { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; AppDelegate *appDelegate = [UIApplication sharedApplication].delegate; + UIImage *image = [imageInfo objectForKey:@"image"]; NSString *imageName = [imageInfo objectForKey:@"name"]; - NSString *imagePath = [[appDelegate saveDirectory] stringByAppendingPathComponent:pathWithScale(imageName)]; - [UIImagePNGRepresentation([imageInfo objectForKey:@"image"]) writeToFile:imagePath atomically:YES]; + NSString *imagePath = [[appDelegate saveDirectory] stringByAppendingPathComponent:pathWithScale(imageName, [image scale])]; + [UIImagePNGRepresentation(image) writeToFile:imagePath atomically:YES]; [self performSelectorOnMainThread:@selector(incrementSaveCounter) withObject:nil waitUntilDone:YES]; [pool drain]; } diff --git a/UIKit_Artwork_Extractor_Prefix.pch b/UIKit_Artwork_Extractor_Prefix.pch index 1cb1cda..0d26f05 100644 --- a/UIKit_Artwork_Extractor_Prefix.pch +++ b/UIKit_Artwork_Extractor_Prefix.pch @@ -10,6 +10,10 @@ @interface UIScreen (iOS4) @property(nonatomic,readonly) CGFloat scale; @end + +@interface UIImage (iOS4) +@property(nonatomic,readonly) CGFloat scale; +@end #endif #endif diff --git a/main.m b/main.m index 4c2034e..a2d4eda 100644 --- a/main.m +++ b/main.m @@ -9,7 +9,7 @@ #import #import -CGFloat UIScreen_scale(id self, SEL _cmd) +CGFloat iOS3_scale(id self, SEL _cmd) { return 1.0; } @@ -18,10 +18,12 @@ int main(int argc, char *argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; - // -[UIView alpha] has the same method signature as -[UIScreen scale] + // -[UIView alpha] has the same method signature as -[UIScreen/UIImage scale] Method alpha = class_getInstanceMethod([UIView class], @selector(alpha)); if (![UIScreen instancesRespondToSelector:@selector(scale)]) - class_addMethod([UIScreen class], @selector(scale), (IMP)UIScreen_scale, method_getTypeEncoding(alpha)); + class_addMethod([UIScreen class], @selector(scale), (IMP)iOS3_scale, method_getTypeEncoding(alpha)); + if (![UIImage instancesRespondToSelector:@selector(scale)]) + class_addMethod([UIImage class], @selector(scale), (IMP)iOS3_scale, method_getTypeEncoding(alpha)); int retVal = UIApplicationMain(argc, argv, nil, nil); [pool release];