iPhoneシュミレーターのカメラロール画像を取り出す
備忘録:シュミレーター内に保存された写真は下記の場所に保存されている。
/User/ユーザー名/Library/Application Support/iPone Simulator/SDKバージョン/Media/DCIM/100APPLE
以下のような感じで、アプリ画面のスクリーンショットを撮ったりすると、高解像度の画像が得られて便利。
#import <QuartzCore/CALayer.h> - (void)getScreenShot { //現在のスクリーンショットを生成 CGRect screenRect = [[UIScreen mainScreen] bounds]; UIGraphicsBeginImageContext(screenRect.size); CGContextRef ctx = UIGraphicsGetCurrentContext(); [[UIColor blackColor] set]; CGContextFillRect(ctx, screenRect); [self.layer renderInContext:ctx]; NSData *pngData = UIImagePNGRepresentation( UIGraphicsGetImageFromCurrentImageContext()); UIImage *retImage = [[UIImage imageWithData:pngData] retain]; UIGraphicsEndImageContext(); //ローカルに保存 UIImageWriteToSavedPhotosAlbum(retImage, self, @selector(image:didFinishSavingWithError:contextInfo:), nil); } - (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void*)contextInfo { if (!error) { NSLog(@"Error %@", [error localizedDescription]); } }