ipad - Iphone sdk 在没有整个上下文的情况下保存图纸

标签 ipad ios4 mkmapview mapkit core-location

我想从我的 iPhone 应用程序中捕获我的 View 屏幕。我有白色背景 View ,并使用此方法在该 View 的图层上画了一条线。

- (void)draw {
    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSaveGState(context);
    if (self.fillColor) {
        [self.fillColor setFill];
        [self.path fill];
    }
    if (self.strokeColor) {
        [self.strokeColor setStroke];
        [self.path stroke];
    }

    CGContextRestoreGState(context);
}



- (void)drawRect:(CGRect)rect {
    // Drawing code.
    for (<Drawable> d in drawables) {
        [d draw];
    }
    [delegate drawTemporary];
}

我使用委托(delegate)方法在图层上画线。 这是我从中获得帮助的项目链接。 https://github.com/search?q=dudel&type=Everything&repo=&langOverride=&start_value=1

现在,当我使用以下上下文方法保存绘图时,我成功地保存了它,没有那个白色背景。

drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();

但是当我使用以下 Bezier Pathe 方法时,我无法在没有白色背景的情况下保存绘图,它会保存整个屏幕,即该绘图及其背景。

UIGraphicsBeginImageContext(self.view.bounds.size);
    [dudelView.layer renderInContext:UIGraphicsGetCurrentContext()];
    //UIImage *finishedPic = UIGraphicsGetImageFromCurrentImageContext();

那么谁能帮我我怎么才能在这个应用程序中只保存这里的绘图。

最佳答案

(您已将此标记为与 MapKit 相关,但未提及 MapKit。)

为什么不将绘图序列分成三个 block ?

  1. 按照您的描述将您的路径绘制到图像上下文中并获取 UIImage。
  2. 绘制背景色。
  3. 绘制 UIImage。

然后您也可以将 UIImage 用于您的“屏幕截图”。

我还应该注意,如果您在捕获的 UIImage 中唯一不想要的是背景颜色,您最好创建一个 UIImageView,设置它的背景颜色(- setBackgroundColor:),并将其图像设置为您的 UIImage。

UIImageView 内部有许多优化,使其能够以比自定义 -drawRect: 实现更高的性能显示图形。

关于ipad - Iphone sdk 在没有整个上下文的情况下保存图纸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7631243/

相关文章:

ios - 如何在苹果 map 上加载JSON数据以放置标记IOS

iPhone 绘画应用程序(基于 glPaint)。与白色背景混合

ios - SDK 4.2 中未检测到 NSURLDownload

ios - 如何在 Swift 3 中显示 MKCircle

javascript - 摇动ios设备时加载随机图像

iOS 4 : Is it possible to show Local Notifications during a Telephony Call?

iphone - 使用 CLLocationManager 的正确方法(开始/停止更新用户位置)

具有部分可见的下一个和上一个 View 的 iOS 滑动 View

css - 如何用Bootstrap确认不同的移动平台?

css - 网站仅在 iPad 上被切断