I'm interested in creating an NSImageRep subclass that can hold double precision values. The standard NSBitmapImageRep can hold single precision floats, but chokes on doubles. I like that the NSBitmapImageRep exposes the data buffer for manipulation, and I'd like to retain the ability to manipulate the data in place rather than manipulate a separate buffer that I'll need to convert into an image for display.
我有兴趣创建一个可以保存双精度值的NSImageRep子类。标准的NSBitmapImageRep可以保存单精度浮点数,但是双精度时会出现扼流圈。我喜欢NSBitmapImageRep暴露数据缓冲区以进行操作,我希望保留在适当的位置操作数据的能力,而不是操作我需要转换为图像进行显示的单独缓冲区。
I think subclassing is fairly straight forward except I'm not sure how to handle the most basic part: drawing the image. The documentation lists -draw as a method I need to implement, which makes sense, but what is the best way to draw a bitmap?
我认为子类化是相当直接的,除了我不知道如何处理最基本的部分:绘制图像。文档列表-draw作为我需要实现的方法,这是有道理的,但绘制位图的最佳方法是什么?
I saw one hesitant suggestion to draw lots of little rectangles, one per pixel presumably: How to Implement Custom Image representation for NSImage
我看到一个犹豫不决的建议,即绘制大量的小矩形,大概是每个像素一个:如何为NSImage实现自定义图像表示
Is there a more efficient approach? I've looked and can't find a worked example of a custom NSImageRep with bitmap data-- most examples use vector data.
有更有效的方法吗?我看了,找不到一个带有位图数据的自定义NSImageRep的实例 - 大多数例子都使用矢量数据。
Also, I find it interesting that the method to implement is simply -draw, and not any form of bounded draw. Is there a way to determine what the current clipping region is from within the NSImageRep or something to avoid drawing parts of the image that aren't necessary?
此外,我觉得有趣的是,实现的方法只是-draw,而不是任何形式的有界绘制。有没有办法确定NSImageRep中当前剪切区域是什么,或者是什么来避免绘制不必要的图像部分?
1 个解决方案
#1
1
I’m sure you’ve found a solution for this post by this point, but here’s my findings if you’re still interested.
我相信你已经找到了这个帖子的解决方案,但是如果你还有兴趣的话,这是我的发现。
What I’ve found in implementing my own NSImageRep
is that there are many inefficient ways of doing it, and that you don’t necessarily have to implement only the starkly simple -(BOOL)draw
method. If you provide an implementation of -(BOOL)drawInRect:
, it will be used instead in most cases. In fact, in my NSImageRep
subclass, I have yet to see -(BOOL)draw
being called when -(BOOL)drawInRect:
is present.
我在实现自己的NSImageRep时发现的是,有许多低效的方法,而且你不一定只需要实现简单的 - (BOOL)绘制方法。如果您提供 - (BOOL)drawInRect:的实现,则在大多数情况下将使用它。事实上,在我的NSImageRep子类中,当 - (BOOL)drawInRect:存在时,我还没有看到 - (BOOL)绘制被调用。
For the actual drawing, I’ve been using Core Graphics, which allows you to create images from raw data and draw it with a great deal of control and precision, all while being extremely fast. My representation is still rather crude, yet it’s fast even when dealing with large images.
对于实际的绘图,我一直在使用Core Graphics,它允许您从原始数据创建图像并以极大的控制和精度绘制它,同时非常快。我的表现仍然相当粗糙,但即使处理大型图像也很快。
The whole subject direly lacks documentation, likely due to there being little need for additional representations outside of the old standards (TIFF, PNG, JPEG, etc). It’s rather frustrating to do research on so if I get the time I’ll see about writing up a blog post detailing everything I’ve run across.
整个主题缺乏文档,可能是因为除了旧标准(TIFF,PNG,JPEG等)之外几乎不需要额外的表示。如果我得到时间,我会看到撰写一篇详细介绍我遇到的所有内容的博客文章,那么进行研究是相当令人沮丧的。
#1
1
I’m sure you’ve found a solution for this post by this point, but here’s my findings if you’re still interested.
我相信你已经找到了这个帖子的解决方案,但是如果你还有兴趣的话,这是我的发现。
What I’ve found in implementing my own NSImageRep
is that there are many inefficient ways of doing it, and that you don’t necessarily have to implement only the starkly simple -(BOOL)draw
method. If you provide an implementation of -(BOOL)drawInRect:
, it will be used instead in most cases. In fact, in my NSImageRep
subclass, I have yet to see -(BOOL)draw
being called when -(BOOL)drawInRect:
is present.
我在实现自己的NSImageRep时发现的是,有许多低效的方法,而且你不一定只需要实现简单的 - (BOOL)绘制方法。如果您提供 - (BOOL)drawInRect:的实现,则在大多数情况下将使用它。事实上,在我的NSImageRep子类中,当 - (BOOL)drawInRect:存在时,我还没有看到 - (BOOL)绘制被调用。
For the actual drawing, I’ve been using Core Graphics, which allows you to create images from raw data and draw it with a great deal of control and precision, all while being extremely fast. My representation is still rather crude, yet it’s fast even when dealing with large images.
对于实际的绘图,我一直在使用Core Graphics,它允许您从原始数据创建图像并以极大的控制和精度绘制它,同时非常快。我的表现仍然相当粗糙,但即使处理大型图像也很快。
The whole subject direly lacks documentation, likely due to there being little need for additional representations outside of the old standards (TIFF, PNG, JPEG, etc). It’s rather frustrating to do research on so if I get the time I’ll see about writing up a blog post detailing everything I’ve run across.
整个主题缺乏文档,可能是因为除了旧标准(TIFF,PNG,JPEG等)之外几乎不需要额外的表示。如果我得到时间,我会看到撰写一篇详细介绍我遇到的所有内容的博客文章,那么进行研究是相当令人沮丧的。