带参数的UIGraphicsBeginImageContext

use*_*878 12 iphone iphone-sdk-3.0

我在我的应用程序中截取屏幕截图.我可以截取屏幕截图.

现在我想通过指定x和y坐标来截取屏幕截图.那可能吗?

UIGraphicsBeginImageContext( self.view.bounds.size );
[self.view.layer renderInContext:UIGraphicsGetCurrentContext(  )];
UIImage* aImage = UIGraphicsGetImageFromCurrentImageContext(  );
Run Code Online (Sandbox Code Playgroud)

ken*_*ytm 18

UIGraphicsBeginImageContext(self.view.bounds.size);
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(c, 0, -40);    // <-- shift everything up by 40px when drawing.
[self.view.layer renderInContext:c];
UIImage* viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Run Code Online (Sandbox Code Playgroud)

  • @Barbgal:不.`CGSize size = self.view.bounds.size; UIGraphicsBeginImageContext(CGSizeMake(size.width,size.height-40)); CGContextRef c = UIGraphicsGetCurrentContext();` (2认同)