简体   繁体   English

什么是图形上下文? (iOS)

[英]What is a graphic context? (iOS)

What exactly is a graphic context?究竟什么是图形上下文? When drawing with Core Graphic we get a reference to the context.使用 Core Graphic 绘图时,我们会获得对上下文的引用。 When I look at the documentation it seems like it is an object or so that take care of the correct drawing whether it is for printing, device, pdf and so on.当我查看文档时,它似乎是一个对象,它负责处理正确的绘图,无论是用于打印、设备、pdf 等。

Could anyone help me to understand what a context really is?谁能帮我理解上下文到底是什么? I tried reading the documentation but I do not understand.我尝试阅读文档,但我不明白。 Is it an object that contains information(meta-data) about a system or something?它是一个包含有关系统或其他东西的信息(元数据)的对象吗?

Thanks in advance提前致谢

"it seems like it is an object or so that take care of the correct drawing whether it is for printing, device, pdf and so on." “它似乎是一个对象,无论是用于打印、设备、pdf 等,它都需要处理正确的绘图。”

Exactly correct.完全正确。

You simply write routines that "really" do some drawing (but it could be to anywhere, to any type of thing or device).您只需编写“真正”进行一些绘图的例程(但它可以用于任何地方,任何类型的事物或设备)。 You don't have to worry about ANYTHING other than drawing in the abstract ... lines, circles, typography, colours and other such nonsense.除了抽象地绘画之外,您不必担心任何事情……线条、圆圈、排版、颜色和其他类似的废话。

-(void)happyDrawing
-(void)sadDrawing
-(void)fancyDrawing

Then -- amazingly -- you can use those anywhere.然后——令人惊讶的是——你可以在任何地方使用它们。

-(void)makeSomeFiles
   {
   .. set up a context for making files
   .. happyDrawing
   }
-(void)makeATruGrayScaleBitmap
   {
   .. set up a context for making a gray bitmap
   .. happyDrawing
   }
-(void)drawRect
   {
   .. drawing on your Lisa screen
   .. happyDrawing
   }
-(void)drawRect
   {
   .. drawing on your iPad screen
   .. happyDrawing
   }
-(void)printAPage
   {
   .. set up a context for printing
   .. happyDrawing
   }

I hope it helps!我希望它有帮助!

简而言之,图形在实际呈现之前被渲染或绘制的区域。

The graphics context determines how you are drawing to the screen, be it OpenGL or some 2D library.图形上下文决定了如何在屏幕上绘制,无论是 OpenGL 还是某些 2D 库。 You should know this.你应该知道这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM