【问题标题】:iPhone: can i save the screen or take screen shot to practicular area of viewiPhone:我可以保存屏幕或截屏到特定的视图区域吗
【发布时间】:2012-07-16 19:51:43
【问题描述】:

我的屏幕上有一张图片,我必须通过截屏来保存这张图片。还有其他方法可以仅保存图像的特定区域吗?

如果有方法,请用一个简单的例子指导我。

【问题讨论】:

标签: iphone


【解决方案1】:

以下代码将允许您只抓取屏幕的一部分,您可以适应全屏

    CGRect screenRect = CGRectMake(0, 0, 200, 200);
UIGraphicsBeginImageContext(screenRect.size);

CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextFillRect(ctx, screenRect);

[self.view.layer renderInContext:ctx];

UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

    //if you want to save this image to the photo album uncomment the next line
//UIImageWriteToSavedPhotosAlbum(newImage, nil, nil, nil);
UIGraphicsEndImageContext();

如果您只是想截取屏幕截图,只需同时按下主页和顶部按钮,每次执行此操作时都会将屏幕截图放入相册中

【讨论】:

    【解决方案2】:

    如果您需要一种编程方式来实现这一点,您可以使用:

    [[NSImage alloc] initWithData:[view dataWithPDFInsideRect:[view bounds]]];
    

    【讨论】:

    • 谢谢你,如果我有任何问题,我会试试这个并回复你
    【解决方案3】:

    尝试同时按下主页和关闭/电源按钮。

    【讨论】:

    • 嗨 weltraumpirat,开个玩笑,我不知道该方法是否退出,所以我问你们
    • 不,我不是在开玩笑。我所做的只是回答你的问题。如果您只是想截取屏幕截图,这就是您的操作方式。也许您应该尝试更具体一些:您要做什么?
    • 嗨weltraumpirat,我的问题是我在增强现实应用程序中工作,我使用两个视图一个是相机,另一个是用于在相机视图上绘制的透明视图,为了保存图像,我放置了视图的 UIButton,之后按下 UIButton 屏幕截图,正在保存 UIButton 图像,我想保存没有 UIButton 的图像,告诉我如何解决这个问题。告诉大家,谢谢
    猜你喜欢
    • 1970-01-01
    • 2015-03-23
    • 1970-01-01
    • 1970-01-01
    • 2012-01-31
    • 2016-04-06
    • 1970-01-01
    • 2021-12-27
    • 2022-01-13
    相关资源
    最近更新 更多