iPhone sdk 保存绘图时没有完整的上下文
我想从我的 iPhone 应用程序捕获我的视图屏幕。我有白色背景视图,并使用此方法在该视图的图层上画一条线。
- (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];
}
我使用委托方法在图层上画线。 这是我从中获得帮助的项目链接。 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();
那么任何人都可以帮助我如何仅在此应用程序中保存绘图。
I want to capture screen of my view from my iPhone app. I have white background view and on that I draw a lines on that view's layer using this method .
- (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];
}
I have use delegate methods to draw lines on layer.
This is the project link from where I get help for this.
https://github.com/search?q=dudel&type=Everything&repo=&langOverride=&start_value=1
Now when I use the following context methods to save the drawing only I successfully save it without that white background.
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
But When I use the following method of Bezier Pathe I cannot save the drawing without its white background,It saves the whole screen i.e. that drawing and its background.
UIGraphicsBeginImageContext(self.view.bounds.size);
[dudelView.layer renderInContext:UIGraphicsGetCurrentContext()];
//UIImage *finishedPic = UIGraphicsGetImageFromCurrentImageContext();
So can anybody help me how can I save the drawing only here in this app.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
(您已将其标记为与 MapKit 相关,但没有提及 MapKit。)
为什么不将绘图序列分成三个块呢?
然后你也可以使用 UIImage 作为你的“屏幕截图”。
我还应该注意,如果您在捕获的 UIImage 中唯一不想要的东西是背景颜色,那么您最好创建一个 UIImageView,设置其背景颜色 (
-setBackgroundColor:< /code>),并将其图像设置为您的 UIImage。
UIImageView 内部有许多优化,使其能够以比自定义
-drawRect:
实现更高的性能显示图形。(You've tagged this as MapKit related, but make no mention of MapKit.)
Why don't you just split your drawing sequence into three chunks?
Then you can use the UIImage for your "screenshot" as well.
I should also note that if the only thing you don't want in your captured UIImage is the background color, you are better off creating a UIImageView, setting its background color (
-setBackgroundColor:
), and setting its image to be your UIImage.UIImageView internally has a number of optimizations that allow it to display graphics with much higher performance than you can get with a custom
-drawRect:
implementation.为什么不直接保存可绘制数组呢?这些都是没有底层图像的图画:)
Why don't you just save the drawables array? Those are all the drawings without the underlying image :)