开发者

Capturing of Screen shot starting from 0,0

I am using following code to make a screen shot

UIGraphicsBeginImageContext(self.view.frame.size);

blendMode:kCGBlendModeClear alpha:1.0];

[self.开发者_如何学Cview.window.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);

return viewImage;

It is working fine but it returns the full screen, and I want a screen shot of a particular Frame, like ( 100,100,200,200), I tried to make changes in:

UIGraphicsBeginImageContext(self.view.frame.size);

But no success.


Try this:

float x = 100;
float y = 100;
CGSize size = CGSizeMake(200,200);

UIGraphicsBeginImageContext(size);
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(c, -x, -y);
[view.layer renderInContext:c];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();


just use three line of code.

    UIGraphicsBeginImageContext(CGSizeMake(320, 480));
    [self.window.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *frame= UIGraphicsGetImageFromCurrentImageContext();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜