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 != 10 && !taken; ++i) {
47 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
49 for (unsigned j(0); j != 1000 && !taken; ++j) {
50 unsigned index = i * 1000 + j;
52 NSString *file = [NSString stringWithFormat:@"%@/IMG_%04u.PNG", apple, index];
54 if (![manager fileExistsAtPath:file isDirectory:&directory]) {
55 [png writeToFile:file atomically:YES];
57 NSString *thm = [NSString stringWithFormat:@"%@/IMG_%04u.THM", apple, index];
58 UIImage *thumb = [image _imageScaledToSize:CGSizeMake(55.0f, 55.0f) interpolationQuality:1];
59 NSData *jpeg = UIImageJPEGRepresentation(thumb);
60 [jpeg writeToFile:thm atomically:YES];
62 NSString *poster = [NSString stringWithFormat:@"%@/.MISC/PosterImage.jpg", dcim, index];
63 [jpeg writeToFile:poster atomically:YES];
65 CFNotificationCenterPostNotification(
66 CFNotificationCenterGetDarwinNotifyCenter(),
67 (CFStringRef) @"PictureWasTakenNotification",
79 NSLog(@"%@ is full", apple);