Iphone 如何拍摄我在quartz 2d中绘制的整个上下文的快照

Iphone 如何拍摄我在quartz 2d中绘制的整个上下文的快照,iphone,ipad,core-graphics,quartz-graphics,quartz-2d,Iphone,Ipad,Core Graphics,Quartz Graphics,Quartz 2d,我想做一个缩略图预览,用户点击一个按钮会看到什么。或者,如果不可能,是否可以将上下文缩放到特定大小。 我的上下文当前使用全屏,即1004x768 px。我希望整个上下文以300x300像素的速度出现,而不会失去它的特性 试试这个 UIGraphicsBeginImageContext(CGSizeMake(self.view.frame.size.height, self.view.frame.size.width)); [self.view.

我想做一个缩略图预览,用户点击一个按钮会看到什么。或者,如果不可能,是否可以将上下文缩放到特定大小。 我的上下文当前使用全屏,即1004x768 px。我希望整个上下文以300x300像素的速度出现,而不会失去它的特性

试试这个

             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];

您是上下文位图上下文吗?不是,我的上下文是CGContextRef context=UIGraphicsGetCurrentContext();你需要在问题中添加更多的信息,说明上下文是如何存在的,它在做什么。。以及要更新的上下文。如果您仅在一个上下文中执行此操作,则可能需要重新考虑您的设计。