//
//  ScreenCapture.m
//  traceWrite
//
//  Created by 今井 彰彦 on 2012/02/24.
//  Copyright (c) 2012 AIG-Soft. All rights reserved.
//

#import "ScreenCapture.h"
#ifdef DEBUG
#import "FileControl2.h"
#endif

UIImage *viewCapture(UIView *view)
// viewキャプチャ
{
	UIImage *capture; 
	
	UIGraphicsBeginImageContext(view.frame.size);
	[view.layer renderInContext:UIGraphicsGetCurrentContext()];
	capture = UIGraphicsGetImageFromCurrentImageContext();
	UIGraphicsEndImageContext();
	
#ifdef DEBUG	//!!test!!
	{
		NSData *imgdata=UIImageJPEGRepresentation(capture,1.0);
		[imgdata writeToFile:makeFullPathForSaveData(@"viewCapture.jpg") atomically:YES];
	}
#endif
	
	return capture;
}

UIImage *screenCapture(void)
{
	UIImage *capture;
	CGRect rect = [[UIScreen mainScreen] bounds];
	
	UIGraphicsBeginImageContext(rect.size);
	[[UIApplication sharedApplication].keyWindow.layer renderInContext:UIGraphicsGetCurrentContext()];
	capture = UIGraphicsGetImageFromCurrentImageContext();
	UIGraphicsEndImageContext();
	
#ifdef DEBUG	//!!test!!
	{
		NSData *imgdata=UIImageJPEGRepresentation(capture,1.0);
		[imgdata writeToFile:makeFullPathForSaveData(@"screenCapture.jpg") atomically:YES];
	}
#endif
	
	return capture;
}
