【问题标题】:Capturing of Screen shot starting from 0,0从 0,0 开始捕获屏幕截图
【发布时间】:2011-04-04 11:54:40
【问题描述】:

我正在使用以下代码进行屏幕截图

UIGraphicsBeginImageContext(self.view.frame.size);

blendMode:kCGBlendModeClear alpha:1.0];

[self.view.window.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);

return viewImage;

它工作正常,但它返回全屏,我想要一个特定框架的屏幕截图,比如( 100,100,200,200),我尝试在以下方面进行更改:

UIGraphicsBeginImageContext(self.view.frame.size);

但没有成功。

【问题讨论】:

    标签: iphone uiimageview


    【解决方案1】:

    试试这个:

    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();
    

    【讨论】:

    • +1 谢谢你,伙计……这对我来说真的是非常非常重要的任务……而且你的伎俩奏效了。
    • 你应该开始在视网膜显示设备上使用 UIGraphicsBeginImageContextWithOptions(size, YES, 2.0)
    【解决方案2】:

    只需使用三行代码。

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

    【讨论】:

    • 不,捕获的区域为 0,0,320,480。问题是如何裁剪 x,y,w,h 的区域。
    猜你喜欢
    • 1970-01-01
    • 2011-10-13
    • 1970-01-01
    • 1970-01-01
    • 2012-01-20
    • 2017-12-03
    • 2023-03-29
    • 2014-03-07
    • 1970-01-01
    相关资源
    最近更新 更多