我想对用户点击按钮时会看到的内容进行缩略图预览。或者,如果这不可能,则可以将上下文缩放到特定大小。 我的上下文目前使用全屏,即1004x768像素。我希望这整个背景能够以300x300像素的速度出现而不会失去其身份。
答案 0 :(得分:0)
试试这个
UIGraphicsBeginImageContext(CGSizeMake(self.view.frame.size.height, self.view.frame.size.width));
[self.view.layer renderInContext:UIGraphicsGetCurrentContext() ];
UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
NSLog(@"Screen Shot : %@",screenshot);
UIGraphicsEndImageContext();
// ATTACHING A SCREENSHOT
NSData *myData = UIImagePNGRepresentation(screenshot);
NSDate *date = [NSDate date];
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"mm:ss"];
NSString *timestamp = [df stringFromDate:date];
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *fullImagePath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"Image_%@.png",timestamp]];
NSLog(@"TimeStamp = %@",timestamp);
NSLog(@"Image Path : %@",fullImagePath);
[myData writeToFile:fullImagePath atomically:YES];