1 #import <CoreFoundation/CFData.h>
2 #import <CoreGraphics/CGImage.h>
3 #import <Foundation/Foundation.h>
4 #import <UIKit/UIImage-UIImageInternal.h>
9 #define _trace() NSLog(@"_trace():%s:%u", __FILE__, __LINE__)
11 extern "C" CGImageRef UIGetScreenImage();
12 extern "C" NSData *UIImagePNGRepresentation(UIImage *);
13 extern "C" NSData *UIImageJPEGRepresentation(UIImage *);
15 int main(int argc, char *argv[]) {
16 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
18 CGImageRef screen = UIGetScreenImage();
19 UIImage *image = [UIImage imageWithCGImage:screen];
20 NSData *png = UIImagePNGRepresentation(image);
23 NSString *dcim = [NSString stringWithFormat:@"%@/Media/DCIM", NSHomeDirectory()];
24 NSString *apple = [NSString stringWithFormat:@"%@/999APPLE", dcim];
26 NSFileManager *manager = [NSFileManager defaultManager];
29 if (![manager fileExistsAtPath:apple isDirectory:&directory]) {
31 createDirectoryAtPath:apple
32 withIntermediateDirectories:YES
36 NSLog(@"%@ does not exist and cannot be created", apple);
39 } else if (!directory) {
40 NSLog(@"%@ exists and is not a directory", apple);
46 for (unsigned i(0); i != 100 && !taken; ++i) {
47 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
49 for (unsigned j(0); j != 100 && !taken; ++j) {
50 unsigned index = i * 100 + j;
54 NSString *file = [NSString stringWithFormat:@"%@/IMG_%04u.PNG", apple, index];
56 if (![manager fileExistsAtPath:file isDirectory:&directory]) {
57 [png writeToFile:file atomically:YES];
59 NSString *thm = [NSString stringWithFormat:@"%@/IMG_%04u.THM", apple, index];
60 UIImage *thumb = [image _imageScaledToSize:CGSizeMake(55.0f, 55.0f) interpolationQuality:1];
61 NSData *jpeg = UIImageJPEGRepresentation(thumb);
62 [jpeg writeToFile:thm atomically:YES];
64 NSString *poster = [NSString stringWithFormat:@"%@/.MISC/PosterImage.jpg", dcim, index];
65 [jpeg writeToFile:poster atomically:YES];
67 CFNotificationCenterPostNotification(
68 CFNotificationCenterGetDarwinNotifyCenter(),
69 (CFStringRef) @"PictureWasTakenNotification",
75 NSLog(@"DONE: %@", file);
83 NSLog(@"%@ is too full", apple);