简体   繁体   English

从CIImage绘制UIImage在drawRect中:

[英]Draw UIImage From CIImage In drawRect:

I'm learning about drawing UIImages and CGImages, using CIFilters etc. To test my knowledge I made a small test app with sliders that programmatically change the color of a potion sprite and display it on screen (using a CIHueBlendMode CIFilter). 我正在学习使用CIFilters等绘制UIImages和CGImages的知识。为了测试我的知识,我制作了一个带有滑块的小型测试应用程序,该滑块可通过编程方式更改药水精灵的颜色并将其显示在屏幕上(使用CIHueBlendMode CIFilter)。 After I finished, I wanted to cleanup the relatively lengthy code and noticed that instead of going from the filter's outputted CIImage to a CGImage and then a UIImage, I could go directly from a CIImage to UIImage using UIImage's imageWithCIImage: method. 完成后,我想清理相对冗长的代码,并注意到,可以使用UIImage的imageWithCIImage:方法直接从CIImage转换为UIImage,而不是从过滤器的输出CIImage移至CGImage,然后是UIImage。

However, when I tried to draw the resultant UIImage using drawInRect:, nothing was drawn. 但是,当我尝试使用drawInRect:绘制所得的UIImage时,没有绘制任何内容。 Going through the CGImage stage rectifies this, of course. 当然,通过CGImage阶段可以解决此问题。 My understanding of this is that making a UIImage from a CIImage results in a NULL CGImage property in the UIImage, which is used in drawInRect: . 我对此的理解是, 从CIImage制作UIImage会导致UIImage中的NULL CGImage属性,该属性用于drawInRect:中 Is this correct? 这个对吗? If so, is there a better way to display a CIImage than to go through CGImage followed by UIImage? 如果是这样,是否有比通过CGImage和UIImage更好的显示CIImage的方法? I could just draw a CGImage made with the CIImage, but that would flip the image, which leads to another question. 我可以只绘制一个用CIImage制作的CGImage,但是那样会使图像翻转,从而引发另一个问题。 Currently, I wrap anything I draw in a UIImage first to take care of flipping. 目前,我先将绘制的所有图像包装在UIImage中,以进行翻转。 Is there another, more efficient way? 还有另一种更有效的方法吗?

Too Long; 太长; Didn't Read: Is there a better way to draw CIImages other than turning it into a CGImage, then a UIImage and drawing that? 没看过:除了将CIImages转换为CGImage,然后将UIImage并进行绘制之外,还有更好的方法来绘制CIImages吗? What's the best way to handle flipping when drawing CGImages? 绘制CGImage时处理翻转的最佳方法是什么?

Thanks to anyone who can answer some of my questions. 感谢任何可以回答我一些问题的人。 :) :)

After doing some research into what a CIImage is, I realize now that you cannot skip the step of making a CGImage from the CIImage, and even if you could, it wouldn't really be any more efficient, since you'd still have to process the CIImage regardless. 在研究了CIImage是什么之后,我现在意识到您不能跳过从CIImage制作CGImage的步骤,即使可以,它实际上也不会更加有效,因为您仍然必须无论如何处理CIImage。 A CIImage is not really an image, as noted in Apple's documentation , which is processed when it's turned into a CGImage. 正如Apple文档中所述 ,CIImage并不是真正的图像,当它变成CGImage时会被处理。 That's also why if I use Time Profiler on my project I see that 99% of my time in my drawRect: method is spent on createCGImage:, and not using CIFilters. 这就是为什么如果在项目上使用Time Profiler的原因,我发现我在drawRect:方法中有99%的时间都花在createCGImage:上,而不是使用CIFilters。

As for the most efficient way to cope with the coordinate system change between Core Graphics and the iPhone, it seems that wrapping the object in a UIImage instance is the easiest (not sure about best) way to go. 至于处理Core Graphics和iPhone之间的坐标系更改的最有效方法,看来将对象包装在UIImage实例中是最简单(不确定最好)的方法。 It's simple, and relatively efficient. 这很简单,而且相对有效。 Another option would be to transform the graphics context. 另一个选择是转换图形上下文。


If I don't get a better answer than my own within three days, I'll mark it as accepted. 如果三天内没有收到比我自己的答案更好的答案,我会将其标记为已接受。

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

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